Q:

Python, Convert bson output of mongodump to array of json objects (dictionaries)

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

A:

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) 

