[SERVER-9958] $setOnInsert should allow _id to be set Created: 18/Jun/13 Updated: 28/Oct/15 Resolved: 20/Nov/13 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Write Ops |
| Affects Version/s: | None |
| Fix Version/s: | 2.5.4 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Gordon Roylance | Assignee: | Scott Hernandez (Inactive) |
| Resolution: | Done | Votes: | 6 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Participants: | |||||||||||||||||
| Description |
|
Allow setting the _id field if an update does an insert (upsert true case). Original Description: ,{$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. |
| Comments |
| Comment by Scott Hernandez (Inactive) [ 20/Nov/13 ] | |||||
|
This now works in the dev release and soon in 2.6.0 stable release:
| |||||
| Comment by Tim S [ 28/Oct/13 ] | |||||
|
This is killing me, I find it so hard to figure out how to do atomic operations with mongo and now a poor design choice for $setOnInsert and _id is not being fixed for at least six months. | |||||
| Comment by Taha Jahangir [ 21/Oct/13 ] | |||||
|
The error message is `Mod on _id is not allowed`, but actually this is not a `modification`, so logically we should allow _id in $setOnInsert. The real use-case of this issue (for me) is where:
| |||||
| Comment by Scott Hernandez (Inactive) [ 08/Jul/13 ] | |||||
|
If the _id field is known beforehand then using it in the query will produce the desired document/update. There is no workaround if the _id is not a known constant for the document and can be used in the query. | |||||
| Comment by Scott Hernandez (Inactive) [ 18/Jun/13 ] | |||||
|
Currently $set/$setOnInsert doesn't allow setting the _id field at all. I have changed this to a feature request since this is the currently designed behavior. |