Noob Question, please help

agolangf · · 470 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi reddit,</p> <p>I have recently started learning go. I work on nodejs and MongoDb. While working with MongoDb on go, I am stuck and need your help. My MongoDb collection has very unstructred data and cannot be mapped to a struct , I want to query collection and get the result. Mgo requires me to map my result to a struct and I cant do that. I looked at mgo documentation but got nothing. Stackoverflow search is also futile. Thanks in advance. </p> <hr/>**评论:**<br/><br/>danredux: <pre><p>Can&#39;t be mapped to a struct? That&#39;s your issue, everything can be mapped to a struct. Try giving it an empty interface and see what it puts in.</p> <p>Also, we need to see an example of the unstructured data, just remove anything private.</p></pre>iAmNotThatGuyJeez: <pre><p>Hi dan, The collection has documents that has irregularities in key names thus mapping them to struct is hard. Although i figured that slice of bson.M works with Find All query. Thx for reply. </p></pre>danredux: <pre><p>map[string]interface{} is an OK type, if it helps. It lets arbitrary strings go in as keys. Glad you worked it out, though.</p></pre>pierrrre: <pre><p>map it to a bson.M</p></pre>iAmNotThatGuyJeez: <pre><p>Hi bson.M only works with find One. Bson. D works with find all but returns nil. I want to query all. </p></pre>pierrrre: <pre><p>[]bson.M</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

470 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传