我尝试使用以下命令读取bson文件:
import bson
input_dir='/path/to/file/dir/'
bson_stats =open(os.path.join(input_dir,'stats.bson'),'rb')
bson_stats = bson.loads(bson_stats.read())
当我尝试访问bson_stats
时,我仅获得一行数据,但没有获得全部数据。
这是我第一次玩bson文件。我的问题是:
链接到stats.bson
文件:
https://drive.google.com/file/d/1N71hRafOm_6xWNsUfxcr5Sm0fQwydd1a/view?usp=sharing
答案 0 :(得分:1)
BSON (Binary JSON) Encoding and Decoding
>>> with open('stats.bson', 'rb') as f:
... data = bson.decode_all(f.read())
... print data
[{u'CodeGare': u'057', u'TrainEnRetard': 0, u'GareJour': u'2018-03-23_057', u'TotalTrains': 0, u'Date': u'2018-03-23', u'_id': ObjectId('5ab5a312d909c48f43e26cb5')}, {u'CodeGare': u'063', u'TrainEnRetard': 4, u'GareJour': u'2018-03-23_063', u'TotalTrains': 4, u'Date': u'2018-03-23', u'_id': ObjectId('5ab5a312d909c48f43e26cb8')}, {u'CodeGare': u'067', u'TrainEnRetard': 4, u'GareJour': u'2018-03-23_067', u'TotalTrains': 4, u'Date': u'2018-03-23', u'_id': ObjectId('5ab5a312d909c48f43e26cbb')}, {u'CodeGare': u'071', u'TrainEnRetard': 4, u'GareJour': u'2018-03-23_071', u'TotalTrains': 4, u'Date': u'2018-03-23', u'_id': ObjectId('5ab5a312d909c48f43e26cbe')}, {u'CodeGare': u'077', u'TrainEnRetard': 3, u'GareJour': u'2018-03-23_077', u'TotalTrains': 3, u'Date': u'2018-03-23', u'_id': ObjectId('5ab5a312d909c48f43e26cc1')}