File tree Expand file tree Collapse file tree 1 file changed +2
-2
lines changed
packages/models/src/models Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Original file line number Diff line number Diff line change @@ -174,7 +174,7 @@ export abstract class BaseRaw<
174174 public findOneAndUpdate ( query : Filter < T > , update : UpdateFilter < T > | T , options ?: FindOneAndUpdateOptions ) : Promise < WithId < T > | null > {
175175 this . setUpdatedAt ( update ) ;
176176
177- if ( options ?. upsert && ! ( '_id' in update || ( update . $set && '_id' in update . $set ) ) ) {
177+ if ( options ?. upsert && ! ( '_id' in update || ( update . $set && '_id' in update . $set ) ) && ! ( '_id' in query ) ) {
178178 update . $setOnInsert = {
179179 ...( update . $setOnInsert || { } ) ,
180180 _id : new ObjectId ( ) . toHexString ( ) ,
@@ -251,7 +251,7 @@ export abstract class BaseRaw<
251251 updateOne ( filter : Filter < T > , update : UpdateFilter < T > , options ?: UpdateOptions ) : Promise < UpdateResult > {
252252 this . setUpdatedAt ( update ) ;
253253 if ( options ) {
254- if ( options . upsert && ! ( '_id' in update || ( update . $set && '_id' in update . $set ) ) ) {
254+ if ( options . upsert && ! ( '_id' in update || ( update . $set && '_id' in update . $set ) ) && ! ( '_id' in filter ) ) {
255255 update . $setOnInsert = {
256256 ...( update . $setOnInsert || { } ) ,
257257 _id : new ObjectId ( ) . toHexString ( ) ,
You can’t perform that action at this time.
0 commit comments