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

insert() with a Symbol _id subtly causes a different ID to be used.

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • Environment:
      OS:
      node.js / npm versions:
      Additional info:
    • 1
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Problem Statement/Rationale

      Enterprise [direct: mongos] testDB> db.testColl.insert({_id:Symbol("abc")})
      { acknowledged: true, insertedIds: { '0': Symbol(abc) } }
      
      Enterprise [direct: mongos] testDB> db.testColl.find()
      [ { _id: ObjectId("65734ad410242d79575e87ba") } ]
      

      The above should have either used the ID that I gave, failed the insertion if that ID is unusable, or at least warned that it’s substituting an empty ID. It shouldn’t just quietly do something radically different from what I asked.

      Seen in mongosh 1.10.3.

      Steps to Reproduce

      Retry the above.

      Expected Results

      The above should have either used the _id that I gave, or failed the insertion if (as seems to be the case) that ID can’t be represented in BSON.

      Actual Results

      The document inserted has the ID shown above.

      Additional Notes

      Enterprise [direct: mongos] test> EJSON.serialize({_id:Symbol("abc")})
      {}
      

      ^^ This may relate to the problem.


      AC

      • Add an else case to catch any type we do not explicitly support in the BSON serializer

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            felipe.gasper@mongodb.com Felipe Gasper
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: