MongoDB: BSON for JSON

I am using my own mongoDB driver for node.js. I would like to get some data from a database and send it as a JSON string via HTTP. Is there a way to convert BSON to JSON or directly retrieve data from JSON from a database?

Thanks!

+6
source share
1 answer

In python, you can use simplejson encoder to convert bson to json as follows:

result = db.mycol.find({ ....}) json = simplejson.dumps(result) 

It converts all simple objects, but will have difficulties with others, for example, datetime will not work. The following may work to solve this problem: MongoDB object Serialized as JSON

+2
source

Source: https://habr.com/ru/post/914844/


All Articles