[SERVER-7894] A $setOnChange command would be very helpful Created: 10/Dec/12 Updated: 07/Aug/13 Resolved: 11/Dec/12 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Minor - P4 |
| Reporter: | Ryan Nitz | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Participants: | |||||||||||||
| Description |
|
In the same light as $setOnInsert, $setOnChange would also be incredibly helpful and allow developers to reduce the amount of code they have to write. |
| Comments |
| Comment by Ryan Nitz [ 10/Dec/12 ] | |||||
|
Ok, I did not realize that the server checks to see if the specific/individual field value changed... I thought that it just overwrote anything that was previously there. I am looking for a way to issue updates for infrequently changing data that has the least amount of impact on the server. | |||||
| Comment by Eliot Horowitz (Inactive) [ 10/Dec/12 ] | |||||
|
Your example above is what happens already, so I'm totally confused. | |||||
| Comment by Ryan Nitz [ 10/Dec/12 ] | |||||
|
Yep... that works too. I am not married to any particular name | |||||
| Comment by Scott Hernandez (Inactive) [ 10/Dec/12 ] | |||||
|
Something like $setIfDifferent? | |||||
| Comment by Ryan Nitz [ 10/Dec/12 ] | |||||
|
I think the upsert/insert case would be valid too. The previous value is null/non-existant. | |||||
| Comment by Scott Hernandez (Inactive) [ 10/Dec/12 ] | |||||
|
So you want to specify operations that only happen during the update case, not insert (if upsert is true)? Currently all operation happen independent of the method (update/insert). | |||||
| Comment by Ryan Nitz [ 10/Dec/12 ] | |||||
|
$setOnChange might be a bad name... $updateOnChange? | |||||
| Comment by Ryan Nitz [ 10/Dec/12 ] | |||||
|
In a nutshell, mongo would only change the field value if it differs from what is in place.
The following would not change the field ("version") value:
The following would change the field ("version") value because it is different from what is in place:
|