Details
-
Bug
-
Status: Closed
-
Unknown
-
Resolution: Gone away
-
None
-
None
-
None
-
Not Needed
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.
Attachments
Issue Links
- depends on
-
NODE-4388 Investigate NODE-4387 - Unable to use {upsert: true} with _id not null
-
- Closed
-