Trying to read BSON file, get bson.errors.InvalidBSON: objsize too large
I am currently trying to read a bson file to import it into a database. I can already read the file and print it as as bytes, but I end up just getting an bson.errors.InvalidBSON: objsize too large
error.
This is the code that is trying to decode the file
with zip.open(name) as myfile:
content = myfile.read()
print(content)
print(bson.decode_all(content))
and this is the output i get
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
python pymongo bson
add a comment |
I am currently trying to read a bson file to import it into a database. I can already read the file and print it as as bytes, but I end up just getting an bson.errors.InvalidBSON: objsize too large
error.
This is the code that is trying to decode the file
with zip.open(name) as myfile:
content = myfile.read()
print(content)
print(bson.decode_all(content))
and this is the output i get
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
python pymongo bson
add a comment |
I am currently trying to read a bson file to import it into a database. I can already read the file and print it as as bytes, but I end up just getting an bson.errors.InvalidBSON: objsize too large
error.
This is the code that is trying to decode the file
with zip.open(name) as myfile:
content = myfile.read()
print(content)
print(bson.decode_all(content))
and this is the output i get
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
python pymongo bson
I am currently trying to read a bson file to import it into a database. I can already read the file and print it as as bytes, but I end up just getting an bson.errors.InvalidBSON: objsize too large
error.
This is the code that is trying to decode the file
with zip.open(name) as myfile:
content = myfile.read()
print(content)
print(bson.decode_all(content))
and this is the output i get
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
python pymongo bson
python pymongo bson
asked Nov 27 '18 at 9:49
rehtlawrehtlaw
83
83
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
print(content)
b'[{"_id": {"$oid": "5bf3cf511c9d44000088c376"}, "some": "sort of"}, {"_id": {"$oid": "5bf3cf5c1c9d44000088c377"}, "test": "data"}]'
the bytes in the content variable is json encoded bson, not plain bson
if this is the output format you intend to continue to use, you need to change your code to use bson's JSON utility to load the string into a python object:
with zip.open(name) as myfile:
content = myfile.read()
print(content)
print(bson.json_util.loads(content))
# ^--------------^
# | this stuff
yup, that did it. thanks =]
– rehtlaw
Dec 4 '18 at 9:03
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53496858%2ftrying-to-read-bson-file-get-bson-errors-invalidbson-objsize-too-large%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
print(content)
b'[{"_id": {"$oid": "5bf3cf511c9d44000088c376"}, "some": "sort of"}, {"_id": {"$oid": "5bf3cf5c1c9d44000088c377"}, "test": "data"}]'
the bytes in the content variable is json encoded bson, not plain bson
if this is the output format you intend to continue to use, you need to change your code to use bson's JSON utility to load the string into a python object:
with zip.open(name) as myfile:
content = myfile.read()
print(content)
print(bson.json_util.loads(content))
# ^--------------^
# | this stuff
yup, that did it. thanks =]
– rehtlaw
Dec 4 '18 at 9:03
add a comment |
print(content)
b'[{"_id": {"$oid": "5bf3cf511c9d44000088c376"}, "some": "sort of"}, {"_id": {"$oid": "5bf3cf5c1c9d44000088c377"}, "test": "data"}]'
the bytes in the content variable is json encoded bson, not plain bson
if this is the output format you intend to continue to use, you need to change your code to use bson's JSON utility to load the string into a python object:
with zip.open(name) as myfile:
content = myfile.read()
print(content)
print(bson.json_util.loads(content))
# ^--------------^
# | this stuff
yup, that did it. thanks =]
– rehtlaw
Dec 4 '18 at 9:03
add a comment |
print(content)
b'[{"_id": {"$oid": "5bf3cf511c9d44000088c376"}, "some": "sort of"}, {"_id": {"$oid": "5bf3cf5c1c9d44000088c377"}, "test": "data"}]'
the bytes in the content variable is json encoded bson, not plain bson
if this is the output format you intend to continue to use, you need to change your code to use bson's JSON utility to load the string into a python object:
with zip.open(name) as myfile:
content = myfile.read()
print(content)
print(bson.json_util.loads(content))
# ^--------------^
# | this stuff
print(content)
b'[{"_id": {"$oid": "5bf3cf511c9d44000088c376"}, "some": "sort of"}, {"_id": {"$oid": "5bf3cf5c1c9d44000088c377"}, "test": "data"}]'
the bytes in the content variable is json encoded bson, not plain bson
if this is the output format you intend to continue to use, you need to change your code to use bson's JSON utility to load the string into a python object:
with zip.open(name) as myfile:
content = myfile.read()
print(content)
print(bson.json_util.loads(content))
# ^--------------^
# | this stuff
answered Nov 28 '18 at 20:49
bauman.spacebauman.space
1,170713
1,170713
yup, that did it. thanks =]
– rehtlaw
Dec 4 '18 at 9:03
add a comment |
yup, that did it. thanks =]
– rehtlaw
Dec 4 '18 at 9:03
yup, that did it. thanks =]
– rehtlaw
Dec 4 '18 at 9:03
yup, that did it. thanks =]
– rehtlaw
Dec 4 '18 at 9:03
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53496858%2ftrying-to-read-bson-file-get-bson-errors-invalidbson-objsize-too-large%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown