且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MongoDB:从BSON到JSON

更新时间:2023-11-29 10:35:04

在python中,您可以使用simplejson编码器将bson转换为json,如下所示:

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

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

它将转换所有简单的对象,但会与其他对象发生冲突,例如,日期时间将不起作用.要解决此问题,可以使用以下方法:序列化为JSON的MongoDB对象

It will convert all simple objects, but will have difficulties with others, for example datetime will not work. To deal with this issue the following may work: MongoDB Object Serialized as JSON