Hi reddit,
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.
评论:
danredux:
iAmNotThatGuyJeez:Can't be mapped to a struct? That's your issue, everything can be mapped to a struct. Try giving it an empty interface and see what it puts in.
Also, we need to see an example of the unstructured data, just remove anything private.
danredux: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.
pierrrre:map[string]interface{} is an OK type, if it helps. It lets arbitrary strings go in as keys. Glad you worked it out, though.
iAmNotThatGuyJeez:map it to a bson.M
pierrrre:Hi bson.M only works with find One. Bson. D works with find all but returns nil. I want to query all.
[]bson.M
