What I am looking is equivalent of Document.parse()
in golang, that allows me create bson from json directly? I do not want to create intermediate Go structs for marshal
mongo-go-driver has a function bson.UnmarshalExtJSON that does the job.
mongo-go-driver
bson.UnmarshalExtJSON
Here's the example:
var doc interface{} err := bson.UnmarshalExtJSON([]byte(`{"foo":"bar"}`), true, &doc) if err != nil { // handle error }