mongodb - How to get Mongo documents and return them as a JSON API response -


i'm writing api retrieves mongo documents , return documents json response.

i can creating struct proper field mappings, since i'm not processing these documents, want convert raw data code below json. api return json response.

i have following code:

var raw []bson.raw err = mycollection.find(       bson.m{"name": name}, ).all(&raw) 

i want convert raw json. how that? there better of this other starting create bson.raw?

tech stack: go 1.1 mgo v1  http://godoc.org/labix.org/v1/mgo bson v1 http://godoc.org/labix.org/v1/mgo/bson 

thanks.

unmarshal maps instead:

var maps []bson.m err = mycollection.find(bson.m{"name": name}).all(&maps) 

this way can provide these same maps encoding/json package's marshal function.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -