[SERVER-4175] Upsert prevents custom id from being used when insert is done instead of update Created: 30/Oct/11  Updated: 07/Mar/14  Resolved: 30/Oct/11

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.0.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Mongo User Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: id, upsert
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

The upsert command in mongo db is not allowing a custom id to be used when a new doc is inserted. For example, suppose a collection was created with all the docs having a custom id that is an auto-increment integer. Then, if an upsert is used, the developer is not able to specify an integer as the _id value to be inserted (if an insert is performed instead of an update).

This is breaking the upsert capability on any collection which uses custom ids, since once upserts are used in such a collection, the _id value of any docs inserted as a result of an upsert will use the ObjectId, instead of the custom id as on all other docs in the collection.

The fix would be to enable a $set command to be used in an upsert that specifies a value for _id, but the new _id value is only used if an insert is done instead of an update (since the _id value is immutable on existing docs).

See: http://groups.google.com/group/mongodb-user/browse_thread/thread/40fcaa617ab99873



 Comments   
Comment by Eliot Horowitz (Inactive) [ 02/Nov/11 ]

correct.
See Fix For on SERVER-340 for current status.

Comment by Mongo User [ 30/Oct/11 ]

To confirm until SERVER-340 is implemented, it is impossible to set a custom value for _id on an upsert. Is that correct?

If so, any rough estimate on the ETA for SERVER-340?

Comment by Eliot Horowitz (Inactive) [ 30/Oct/11 ]

_id shouldn't be allowed in a $set
Could be in an $iset
See SERVER-340
Will make a note to make sure _id works

Generated at Thu Feb 08 03:05:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.