如何从Golang中的MongoDB bson.m中制作多行字符串值?
我正在使用Golang创建电报机器人,我需要一些有关如何从Golang中检索多行字符串值的建议,该函数具有与此Python String相同的逻辑,
answer = """1 John 95
2 Sam 89
3 Mike 72"""
我具有一个函数,该函数创建了一个mongoDB请求,该请求使我获取数据在bson.m数据类型中。之后,我需要使用此表格将此查询数据作为单个字符串值发送给用户:
msg := tgbotapi.NewMessage(
update.Message.Chat_ID,
answer,
)
bot.Send(msg)
我真的不知道如何将此bson.m数据转换为单个多行字符串。
我从功能中获得的bson.m响应:
[map[_id:ObjectID("62a4acf2a494a2814238c6e1") bandMember:John name:School12 points:95]
map[_id:ObjectID("62a4acf2a494a2814238c6e2") bandMember:Sam name:School15 points:89]
map[_id:ObjectID("62a4acf2a494a2814238c6e3") bandMember:Mike name:School7 points:72]]
我必须将其插入“答案”的字符串变量(请参见上面的示例),
谢谢!
I'm creating a telegram bot using Golang, and I need some advice on how to retrieve a multiline string value from function in Golang, that has same logic like this Python string
answer = """1 John 95
2 Sam 89
3 Mike 72"""
I have a function that creates a MongoDB request that gets me a data in bson.M datatype. And after that I need to send this queried data to a user as a single string value using this form:
msg := tgbotapi.NewMessage(
update.Message.Chat_ID,
answer,
)
bot.Send(msg)
I don't really know how to transform this bson.M data into a single multiline string.
bson.M response that I get from the function:
[map[_id:ObjectID("62a4acf2a494a2814238c6e1") bandMember:John name:School12 points:95]
map[_id:ObjectID("62a4acf2a494a2814238c6e2") bandMember:Sam name:School15 points:89]
map[_id:ObjectID("62a4acf2a494a2814238c6e3") bandMember:Mike name:School7 points:72]]
And I have to insert it in a string variable of "answer" (see above example)
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
循环浏览文档,并为每个文档提供一条线。加入Newline以获得最终结果。
Loop through the documents and sprintf a line for each document. Join the lines with newline to get the final result.