Trying to read BSON file, get bson.errors.InvalidBSON: objsize too large












1















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









share|improve this question



























    1















    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









    share|improve this question

























      1












      1








      1








      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









      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 27 '18 at 9:49









      rehtlawrehtlaw

      83




      83
























          1 Answer
          1






          active

          oldest

          votes


















          0














          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





          share|improve this answer
























          • yup, that did it. thanks =]

            – rehtlaw
            Dec 4 '18 at 9:03











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          0














          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





          share|improve this answer
























          • yup, that did it. thanks =]

            – rehtlaw
            Dec 4 '18 at 9:03
















          0














          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





          share|improve this answer
























          • yup, that did it. thanks =]

            – rehtlaw
            Dec 4 '18 at 9:03














          0












          0








          0







          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





          share|improve this answer













          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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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



















          • 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




















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)