Hi Venkat
Is it possible to make an perform an updateMany operation which returns a list of updated documents as a result?
I don’t believe so. Both the async and sync versions of the method returns an instance of UpdateResult class, which only returns the count of matched and modified documents. This is similar to the output of the mongo shell after an update operation.
Having said that, the update syntax requires two things: the matching part (which should match the documents to be updated) and the update part (which specifies the update to be performed), so what documents are to be updated and what the document would look like after the update are already reflected in the syntax. Alternatively, the findOneAndUpdate method allows you to return the updated document, although this method can only update one document at a time. Do you have a specific use case in mind that is achieved by returning the updated documents?
Best regards
Kevin
Hi Venkat
I couldn’t find a method which updates all and get the updated document. Hence I was left with using the findOneAndUpdate method, which I have to call multiple times with the right filter query. Hence I was wondering if there are any alternate methods which can help me with this scenario, by reducing the no. of calls to DB.
I understand the pain this caused you, but unfortunately there is no feature currently that can do what you want.
Having said that, I believe SERVER-714 describes the situation you’re looking for. Please watch/comment on the ticket for updates.
Best regards
Kevin