我目前正在尝试读取一个bson文件并将其导入到数据库中。我已经可以读取文件并以字节形式打印出来,但最终我只得到了一个bson.errors.InvalidBSON: objsize too large
的错误。
以下是尝试解码文件的代码:
with zip.open(name) as myfile:
content = myfile.read()
print(content)
print(bson.decode_all(content))
这是我得到的输出结果。
b'[{"_id": {"$oid": "5bf3cf511c9d44000088c376"}, "some": "sort of"}, {"_id": {"$oid": "5bf3cf5c1c9d44000088c377"}, "test": "data"}]'
Traceback (most recent call last):
File "/home/jonas/.envs/mongodb-backup-py-aGZYxULQ/bin/mongo-backup", line 11, in <module>
load_entry_point('mongo-backup-cli', 'console_scripts', 'mongo-backup')()
File "/home/jonas/.envs/mongodb-backup-py-aGZYxULQ/lib/python3.6/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/jonas/.envs/mongodb-backup-py-aGZYxULQ/lib/python3.6/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/jonas/.envs/mongodb-backup-py-aGZYxULQ/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/jonas/.envs/mongodb-backup-py-aGZYxULQ/lib/python3.6/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/jonas/.envs/mongodb-backup-py-aGZYxULQ/lib/python3.6/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/jonas/work/mongodb-backup-py/mongo_backup/cli.py", line 45, in restore
restore_files(uri, db_name, file.name)
File "/home/jonas/work/mongodb-backup-py/mongo_backup/restore.py", line 6, in restore_files
print(read_zip_file(file))
File "/home/jonas/work/mongodb-backup-py/mongo_backup/zip.py", line 24, in read_zip_file
print(bson.decode_all(content))
bson.errors.InvalidBSON: objsize too large