-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
-
Empty show more show less
When inserting a document using insertOne, a successful write mutates the provided argument.
Offending block in collection.js L736, mongodb@2.2.31
// Add _id if not specified if(forceServerObjectId !== true){ for(var i = 0; i < docs.length; i++) { if(docs[i]._id === void 0) docs[i]._id = self.s.pkFactory.createPk(); } }
Reproducible with:
const myObject = Object.freeze({myProp: "hi"}) await db.collection("my-collection).insertOne(myObject) TypeError: Cannot add property _id, object is not extensible (/node_modules/mongodb/lib/collection.js:739:46) at insertOne (/node_modules/mongodb/lib/collection.js:439:3) at /node_modules/mongodb/lib/collection.js:431:5 at Promise (<anonymous>) at Collection.insertOne (/node_modules/mongodb/lib/collection.js:430:10)
- is related to
-
NODE-4837 Do not modify user input on insert operations when adding object ids
- Backlog