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

Unable to stringify extended json for ObjectID from mongo package

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: Not Applicable
    • Component/s: EJSON
    • Labels:
      None
    • 0
    • 0
    • Not Needed
    • Not Needed

      From the ticket:

       

      When I try stringify result from mongdb query I get error.const mongodb =

      require('mongodb');
      const bson = require('bson');
      
      const mongoObjectId = new mongodb.ObjectId();
      
      const bsonObjectId = new bson.ObjectId();
      
      console.log(bson.EJSON.stringify(bsonObjectId)); // {"$oid":"5c092e78f381e590b57377c3"}
      try {
          console.log(bson.EJSON.stringify(mongoObjectId));
      } catch (e) {
          console.error(e) //Error: invalid ObjectId, ObjectId.id must be either a string or a Buffer, but is [{"type":"Buffer","data":[]}]
      } 

            Assignee:
            Unassigned Unassigned
            Reporter:
            matt.broadstone@mongodb.com Matt Broadstone
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: