-
Type:
Task
-
Resolution: Done
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
NODE-4387 Description
What problem are you facing?
I'm trying to upsert a document using the method `findOneAndUpdate` without having an _id: null. I've tried using the $setOnInsert clause but it seems that since the _id should not be manually set the operation is failing.
What driver and relevant dependency versions are you using?
NodeJS client: 3.6.3
Mongodb server: 5.0.4
Steps to reproduce?
const updateClause= {
$set: omit(update, '_id'),
// forbidden
{{ $setOnInsert: { _id: newObjectId() }}}
};{}const res= await this.collection.findOneAndUpdate(
{{
, }}
updateClause, {
upsert: true,
returnOriginal: false
});
Running that, I get this error:
Performing an update on the path '_id' would modify the immutable field '_id'
That said, I cannot upsert a document with an id that is not null. If I try this operation without the $setOnInsert I get the document with _id: null.
- is depended on by
-
NODE-4387 Unable to use {upsert: true} with _id not null
-
- Closed
-