[SERVER-3409] WriteResult should indicate number of docs modified (no-ops excluded) Created: 11/Jul/11 Updated: 28/Oct/15 Resolved: 13/Dec/13 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Write Ops |
| Affects Version/s: | 1.8.2 |
| Fix Version/s: | 2.5.5 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Kyle Banker | Assignee: | Scott Hernandez (Inactive) |
| Resolution: | Done | Votes: | 17 |
| Labels: | gle, update, updated | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||||||
| Linked BF Score: | 0 | ||||||||||||||||||||||||||||||||
| Description |
|
Report both the number of documents ("n") which were matched and have the expected updated values, and the number of docs which were actually changed with a write to the database ("nDocsModified"). Expected:
Note: These changes only apply to the new write commands, not the old wire protocol updates. This means you must be using a new driver/client to see this field in the WriteResults. Old Description ) , {$addToSet: { n: 'foo' }} ) db.getPrevError(); { "err" : null, "updatedExisting" : true, "n" : 1, "nPrev" : 1, "ok" : 1 }updatedExisting should be false in this case, since the document was not, in fact, updated. |
| Comments |
| Comment by Githook User [ 13/Dec/13 ] |
|
Author: {u'username': u'scotthernandez', u'name': u'Scott Hernandez', u'email': u'scotthernandez@gmail.com'}Message: |
| Comment by Jeff Seibert [ 23/Nov/13 ] |
|
Just give up and migrate off Mongo like the rest of us. It's been over 2 years. They don't care and they aren't going to fix this issue. Sorry. |
| Comment by Jeremy Haile [ 23/Nov/13 ] |
|
This is a big problem for me. I currently use redis when adding to sets so that I can know if the element was added or not (and then execute some other behavior) I'd prefer to migrate this code to mongo, but there's no way to know if an element was added when calling $addToSet. |
| Comment by KAWAMORITA Mitsuaki [ 20/Aug/13 ] |
|
It's a big problem for me, too |
| Comment by Piyush Verma [ 02/Nov/12 ] |
|
+1 Infact there are a bunch of Bugs filed around this behaviour. |
| Comment by Adam Reilly [ 17/Aug/12 ] |
|
This would be a pretty crucial feature for us |
| Comment by Tucker B [ 09/Aug/12 ] |
|
+1 agree with Tim. I'm having to use Redis for the parts of my application that use set operations because I need to know whether something was actually added to the set or not. |
| Comment by Tim Oxley [ 13/May/12 ] |
|
+1 this is a really frustrating issue. $addToSet isn't remotely as useful if you can't actually tell if an item was added to the set or not. |
| Comment by Jeff Seibert [ 08/Dec/11 ] |
|
Any chance of bumping the priority on this? It would make the atomic operators radically more useful. Here is an example use case: Restaurants and Patrons. Let's say I want to track which restaurants each patron has been to, and how many unique patrons have been to each restaurant, in O(1) time. Patron: Restaurant: On each visit to a restaurant: IF SUCCESSFUL: }) Without this functionality, the only safe way to do it is query the entire patrons table for people who have been to that restaurant - recomputing the count every time. Yes, the restaurants field can be indexed, but that is still slower than simply knowing to increment it, and feels like a waste. Am I correct in that there is currently no other way to do this? |
| Comment by Scott Hernandez (Inactive) [ 12/Jul/11 ] |
|
It would be great if we could explicitly list the changes. Maybe something like: { $addToSet : ###, $push: ###, $set : ### .... } |
| Comment by Eliot Horowitz (Inactive) [ 12/Jul/11 ] |
|
I don't want to overload updatedExisting. |