[SERVER-28145] add ability to obtain modified flag from findOneAndUpdate result Created: 28/Feb/17  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: tony kerz Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Duplicate
is duplicated by SERVER-66740 findAndModify.lastErrorObject.updated... Closed
Related
related to SERVER-66740 findAndModify.lastErrorObject.updated... Closed
is related to SERVER-42741 getting back both _id of modified doc... Backlog
Assigned Teams:
Query Execution
Participants:

 Description   

my understanding is that updateOne returns a modifiedCount field indicating if a document has actually been modified (i.e. can be used to distinguish if a field has actually changed vs a redundant action of attempting to update a existing field to it's original value).

findOneAndUpdate doesn't appear to communicate that same information such that it is impossible to distinguish the case where an update operation has no overall effect on a document because no field has actually changed from it's original value.

i realize that the existing return value needs to stay consistent for backwards compatibility, but maybe introduce a different method (e.g. updateAndFetch) or a flag to this method (e.g. includeInfo) which will allow a result looking something like:

{
  document: <either original or new document here depending on flag>,
  modifiedCount: <counter indicating whether an actual modification has occurred>
}



 Comments   
Comment by David Golden [ 03/Mar/17 ]

A request for an update should go to the internal SPECS Jira project with "CRUD spec" as the "component" field.

Comment by Charlie Swanson [ 03/Mar/17 ]

There appear to be two related problems here:

  1. The findAndModify command does not report enough information to be able to determine whether the update was a no-op. The update command returns 'nMatched' and 'nModified', which would probably be useful in this context as well.
  2. The CRUD API for findOneAndUpdate only returns the pre or post image of the document, and hides the other information reported by the findAndModify command, which includes a lastErrorObject, which might be useful?

david.golden is there somewhere we can put a request for an update to the CRUD API?

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