从 python 的 .bson 文件恢复数据库
restore database from .bson file for python
我尝试使用以下命令读取 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文件。我的问题是:
- 如何访问 bson 文件中的全部数据?
Link 到 stats.bson
文件:
https://drive.google.com/file/d/1N71hRafOm_6xWNsUfxcr5Sm0fQwydd1a/view?usp=sharing
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')}
我尝试使用以下命令读取 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文件。我的问题是:
- 如何访问 bson 文件中的全部数据?
Link 到 stats.bson
文件:
https://drive.google.com/file/d/1N71hRafOm_6xWNsUfxcr5Sm0fQwydd1a/view?usp=sharing
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')}