I want to read the Mongo format in BSON format in Python and process the data. I use Python's bson package (which I would prefer to use rather than the pymongo dependency), but it does not explain how to read from a file.
Here is what I am trying:
bson_file = open('statistics.bson', 'rb') b = bson.loads(bson_file) print b[0]
But I get:
Traceback (most recent call last): File "test.py", line 11, in <module> b = bson.loads(bson_file) File "/Library/Python/2.7/site-packages/bson/__init__.py", line 75, in loads return decode_document(data, 0)[1] File "/Library/Python/2.7/site-packages/bson/codec.py", line 235, in decode_document length = struct.unpack("<i", data[base:base + 4])[0] TypeError: 'file' object has no attribute '__getitem__'
What am I doing wrong?
source share