问题
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