[SERVER-2769] Provide a way to find out if $addToSet caused a change to the list Created: 16/Mar/11  Updated: 07/Mar/14  Resolved: 02/Nov/12

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Benjamin Darfler Assignee: Unassigned
Resolution: Duplicate Votes: 7
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-3409 WriteResult should indicate number of... Closed
Participants:

 Description   

Using $addToSet there is no way to find if the add changed the list. I would have though that the updatedExisting field in getLastError would reflect if a change was made or not but it doesn't seem to do that.

> db.set.insert(

{ set : ['1','2','3'], _id : "123" }

);
> db.set.update({_id:"123"},{"$addToSet":{ set: '4'}}); db.runCommand("getlasterror");

{ "err" : null, "updatedExisting" : true, "n" : 1, "ok" : 1 }

> db.set.update({_id:"123"},{"$addToSet":{ set: '4'}}); db.runCommand("getlasterror");
{ "err" : null, "updatedExisting" : true, "n" : 1, "ok" : 1

I'm not sure what the best option here is but it would be very useful to know.



 Comments   
Comment by Eliot Horowitz (Inactive) [ 02/Nov/12 ]

Consolidating to SERVER-3409 since it has the most votes.

Comment by Piyush Verma [ 02/Nov/12 ]

The behaviour persists in Version 2.2.0 as well.
Any plans on a fix for this one ?

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