I have dumped a mongodb collection using the mongodump
command. The output is a dump directory which has these files:
dump/
|___coll.bson
|___coll.metadata.json
How can I open the exported files to a array of dictionaries that work in python? I tried the following and none worked:
with open('dump/coll.bson', 'rb') as f:
coll_raw = f.read()
import json
coll = json.loads(coll_raw)
# Using pymongo
from bson.json_util import loads
coll = loads(coll_raw)
ValueError: No JSON object could be decoded
You should try:
from bson import BSON
with open('dump/coll.bson', 'rb') as f:
coll_raw = f.read()
coll = bson.decode_all(coll_raw)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With