Unable to stringify extended json for ObjectID from mongo package

XMLWordPrintableJSON

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

      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
            Reporter:
            Matt Broadstone
            None
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: