[SERVER-33121] Add updated/deleted _id's to response object of updateMany and deleteMany Created: 05/Feb/18  Updated: 09/Feb/18  Resolved: 09/Feb/18

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.6.0, 3.6.1, 3.6.2
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Dexter Esajas Assignee: David Storch
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-714 Allow findandmodify to retreive more ... Open
Related
related to SERVER-11753 Allow findAndModify/Update to use a t... Open
related to SERVER-12858 Return detailed stats from write comm... Backlog
Sprint: Query 2018-02-12
Participants:

 Description   

When running the following code (in Node.js):

collection.updateMany({type: "a"},{"$set":{b: "c"}}, cb)

the response object does not show me which records have been updated.
It only tells me the matchedCount and modifiedCount.

Could you please add an array named something like: "modifiedIds" containing all _id's of the records that have been updated.
This way you do not require two seperate calls to mongodb to update multiple records and get their _id's.

Please also see my stackoverflow question for aditional information and the example.
https://stackoverflow.com/questions/43743931/is-it-possible-to-get-all-the-ids-of-updated-records-in-mongodb-using-updatema



 Comments   
Comment by Dexter Esajas [ 09/Feb/18 ]

Hi david.storch

Thank you for your response, this is indeed what I am looking for!
Already upvoted and watching!

Comment by David Storch [ 09/Feb/18 ]

Hi dexter.esajas,

I think this should be treated as a duplicate of SERVER-714. As Andy mentioned above, it would be nice to allow multi-updates and multi-deletes to return a cursor containing the stream of modified documents. Users should be able to supply a projection which would allow you to project out everything other than the _id field, which would satisfy the particulars of your request.

Note that the server already supports findAndModify, which allows users to perform a single-update or single-delete and return a copy of the modified document with a projection applied. Extending findAndModify's functionality to work for multi-document writes is what you need.

I'm closing this as a duplicate of SERVER-714. Please watch and vote for that ticket, and feel free to reach out with any questions or concerns.

Best,
Dave

Comment by Dexter Esajas [ 09/Feb/18 ]

It seems related in the way that more info could be returned after an operation has been performed I think.
Do I need to clarify my request with more examples or a better description?
The reason I am asking is because I'd like this ticket not to be open for roughly 3 years, like ticket SERVER-12858
I can understand there are more important items on the list though.

Comment by Asya Kamsky [ 08/Feb/18 ]

Something like SERVER-12858 maybe?

Comment by Andy Schwerin [ 07/Feb/18 ]

I haven't thought about this a lot, but occasionally it comes up that users would like to get back a cursor that returns the updated or deleted documents modified by their operations. I can't recall if there are open tickets about that, but perhaps david.storch or asya know.

Comment by Dexter Esajas [ 06/Feb/18 ]

@Andy Schwerin,
Yes good point!

What do you guys think about this functionality/feature?
Do you see the advantage of it as well or do you feel it is unnecessary?

Comment by Andy Schwerin [ 05/Feb/18 ]

You'd probably want to return a cursor of some sort, in case enough docs are modified to overflow a bson array.

Comment by Dexter Esajas [ 05/Feb/18 ]

Hi @Ramon Fernandez,

Thank you for your quick response!

I've missed that it may create a quite some overhead if a user does not require the _id's to be returned.
Maybe make returning the _id's optional through the options of the request like "upsert: true, returnIds: true".

Comment by Ramon Fernandez Marina [ 05/Feb/18 ]

Thanks for your report dexter.esajas; I've tweaked the summary to reflect the improvement nature of this request, and I'm sending this to the Query team for consideration.

Comment by Dexter Esajas [ 05/Feb/18 ]

So this applies for both updateMany and deleteMany.
Thank you for your time!

Generated at Thu Feb 08 04:32:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.