Allow setting the _id field if an update does an insert (upsert true case).
Original Description:
Unable to specify a custom id for the new record using $setOnInsert when calling findAndModify() or update() with upsert = true using a query that does not include the _id. In our scenario the _id is not known before hand, so an additional query has to be used before calling update() or findAndModity() which breaks the atomic nature of the original query. The query worked fine before we wanted to control the _id. When attempting to call db.col.update(
,{$setOnInsert: {_id:"12345"}},
{upsert: true}) we receive the error: Mod on _id not allowed. This doesn't make sense since the record is being created and _id should not already exist.
- is duplicated by
-
SERVER-10685 $setOnInsert prevents setting the _id
- Closed
- related to
-
SERVER-1351 GLE upserted _id field should always be filled in
- Closed