Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3028

Proper way to get Javascript object from loaded BSON file

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON

      https://github.com/mongodb/js-bson/issues/357

      This is my first endeavor with BSON. I wanted to use this in an HTML 5 to store some of my game data. It is currently working with JSON.

      The idea is to save it as BSON. I would either embed or load the file. Then convert this BSON into a Javascript object.

      I use a Python script to create the data. This uses pymongo. A simple sample is:

      data = { 'key0': 'a', 'key1': [ 1, 2, 3 ], 'key2': 'b' }
      with open('test.bson', 'wb') as fp:
          encoded = bson.encode(data)
          fp.write(encoded)
      

      The file test.bson is then loaded in Javascript with either XMLHttpRequest or is embedded via raw-loader.

      However I cannot figure out how to use the library to take convert this file into a Javascript object. Any attempt results in various errors from buffer size issues, needing to convert to Buffer, or some exception being thrown.

      I create a repo here: https://github.com/mobileben/test-bson-js.

      This contains the test data.

      Note that I can decode the file in Python as well as use bsondump to dump the file.

      It's not clear to me why on the JS side it cannot take the same data and decode.

            Assignee:
            Unassigned Unassigned
            Reporter:
            alexander.golin@mongodb.com Alexander Golin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: