mongodb-labs / python-bsonjs

A fast BSON to MongoDB Extended JSON converter for Python - This Repository is NOT a supported MongoDB product
Apache License 2.0
40 stars 10 forks source link

Add support for MongoDB Extended JSON 2.0 #11

Closed ShaneHarvey closed 2 years ago

ShaneHarvey commented 7 years ago

Once libbson 1.7.0 is released with MongoDB Extended JSON 2.0 support we can add support here as well. See https://jira.mongodb.org/browse/CDRIVER-2128.

ShaneHarvey commented 5 years ago

Depends on https://github.com/mongodb-labs/python-bsonjs/issues/15.

behackett commented 3 years ago

@ShaneHarvey is there any further work for this? #15 is resolved.

ShaneHarvey commented 3 years ago

Yes, there is more work to do. We need to actually take advantage of the new libbson APIs that generate extended JSON 2.0. Right now we use bson_as_json, we need to expose the bson_as_canonical_extended_json and/or bson_as_relaxed_extended_json methods.

averhagen commented 3 years ago

@ShaneHarvey I'm looking to use python-bsonjs to take documents from a pymongo cursor, decode those to JSON, and write them out locally to a single JSON file. I'm having a hard time finding documentation on how to do this using python-bsonjs. Any suggestions?

prashantmital commented 3 years ago

Hi @averhagen . You can do something like this:

from pymongo import MongoClient
from bson.raw_bson import RawBSONDocument
import bsonjs

with open('myfile.json', 'w') as f:
    client = MongoClient('<connection_string>', document_class=RawBSONDocument)
    for raw_doc in client.mydb.mycoll.find('<query>'):
        f.write(bsonjs.dumps(raw_doc.raw))
behackett commented 2 years ago

@juliusgeo - see @ShaneHarvey's comment above about the scope of work for this.