[SERVER-16261] Make insert on update (upsert: true) atomic with query + insert Created: 21/Nov/14 Updated: 26/Apr/19 Resolved: 21/Nov/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Write Ops |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | lubinwang | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | duplicates, insert, update, upsert | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Backwards Compatibility: | Major Change | ||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Description |
|
The update operation (with upsert:true) is not currently atomic, for both the query + resulting insert. In highly active environments this will results in duplicated documents or an error due to unique index constraints. The preferred behavior is that all updates will insert a new document or update the existing one, and not result in duplicate documents. |
| Comments |
| Comment by Ian Whalen (Inactive) [ 26/Apr/19 ] |
|
Switching "Drivers Changes Needed" from "Maybe" to "Not Needed" since this was closed as something other than Fixed. |
| Comment by Scott Hernandez (Inactive) [ 21/Nov/14 ] |
|
The documentation here covers the expected and current behavior: http://docs.mongodb.org/manual/reference/method/db.collection.update/#use-unique-indexes While conceptually it would be possible to implement a change like this it would require dramatic changes to performance and the scale of locking needed to ensure no duplicates are created. Due to this extreme cost it is hard to see this as a viable behavioral change nor a good one. |