[SERVER-3326] Support $ positional operator with an upsert Created: 24/Jun/11 Updated: 06/Dec/22 Resolved: 29/Jun/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Write Ops |
| Affects Version/s: | 1.8.2 |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Reid Morrison | Assignee: | Backlog - Query Team (Inactive) |
| Resolution: | Won't Do | Votes: | 45 |
| Labels: | findAndModify, insert, query | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
All |
||
| Issue Links: |
|
||||||||||||||||
| Assigned Teams: |
Query
|
||||||||||||||||
| Participants: | |||||||||||||||||
| Description |
|
According to the documentation, this limitation currently applies to upserts: When performing a findAndModify it would be incredibly powerful to support the insert condition for a document that does not exist. It would save on multiple calls to the Mongo Server and allow for a single atomic update/insert for a document with embedded arrays. Below is JavaScript that can be run in the Mongo Shell to demonstrate this powerful capability: The purpose of these documents is keep track of the last login per user per type of login. And to create the user document if it does not already exist in a single atomic transaction.
|
| Comments |
| Comment by Asya Kamsky [ 29/Jun/19 ] | ||||||||||||
|
You can see some examples here. This can now be done by using various aggregation conditional and array expressions. I believe this can handle the examples/use cases that are mentioned in the comments. The example mentioned:
| ||||||||||||
| Comment by Asya Kamsky [ 28/Jun/17 ] | ||||||||||||
|
On current version (3.4+) this update will return an error:
rather than inserting bad data. |