-
Type: New Feature
-
Resolution: Gone away
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
Requesting a similar function to Map() or an option that enables Map() to recursively convert bson.D to a map.
Due to ordering, bson.D is preferable to bson.M and we're using bson.D exclusively in the developing Go documentation. This type isn't ideal when demonstrating output to users since everything is prepended with "Key" and "Value".
The Map() function provides a workaround for simple documents but breaks down on documents with arrays of documents, as it doesn't convert them.
Example:
var result bson.D err = coll.FindOne(context.TODO(), bson.D{{"title", "The Room"}}).Decode(&result) // end findOne if err != nil { if err == mongo.ErrNoDocuments { // This error means your query did not match any documents. return } panic(err) } // use Map() to quickly convert bson.D to a map output, err := json.MarshalIndent(result.Map(), "", " ") if err != nil { panic(err) } fmt.Printf("%s\n", output)
Unable to find source-code formatter for language: java. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
{ "imdb": [ { "Key": "rating", "Value": 3.5 }, { "Key": "votes", "Value": 25673 }, { "Key": "id", "Value": 368226 } ], "languages": [ "English" ], ... "title": "The Room", }
- related to
-
GODRIVER-2684 Deprecate "bson.D.Map"
- Closed