how to export mongodb without any wrapping with NumberInt(…)?

帅比萌擦擦* 提交于 2021-02-07 07:30:18

问题


I want to export mongodb as json, here is a record:

{"_id":{"$oid":"554f042c0e81bf483e4a4e2f"}, "batch":"3","bz":NumberInt(1)}

the problems is when I use json to loads it:

json.loads('{"_id":{"$oid":"554f042c0e81bf483e4a4e2f"}, "batch":"3","bz":NumberInt(1)}')

it returns ValueError: No JSON object could be decoded. This is because json can not deal with NumberInt(1).

So how can I translate NumberInt(1) to 1 when I export?


回答1:


[UPDATE] IF your mongo collection does not include NumberInt, and mongoexport creates a json document that includes NumberInt, this is a bug. I leave my answer in case anyone has the same issue as I had.

It seems it was indeed a bug

https://jira.mongodb.org/browse/TOOLS-741 that duplicates https://jira.mongodb.org/browse/TOOLS-681 that was fixed in 3.1.4

I tested with 3.1.6 (last dev release) and it works



来源:https://stackoverflow.com/questions/30703171/how-to-export-mongodb-without-any-wrapping-with-numberint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!