[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:
Related
related to SERVER-340 $setOnInsert modifier for upsert Closed
related to SERVER-6566 Support conditional updates: $updates Closed
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.

db.test.insert({ version : '2.2.1'});
db.test.find()
{ "_id" : ObjectId("50c64555731fb8c3d259f5f3"), "version" : "2.2.1" }

The following would not change the field ("version") value:

db.test.update({_id : ObjectId("50c64555731fb8c3d259f5f3"), { $setOnChange : { version : '2.2.1'}}, false, false);

The following would change the field ("version") value because it is different from what is in place:

db.test.update({_id : ObjectId("50c64555731fb8c3d259f5f3"), { $setOnChange : { version : '2.2.2'}}, false, false);

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