Overview
The findAndModify command will be re-implemented in terms of getExecutorDelete() and getExecutorUpdate(). If the findAndModify specifies remove, then it will use getExecutorDelete() to retrieve a PlanExecutor wrapping a DeleteStage. If findAndModify specifies update, then it will use getExecutorUpdate() to retrieve a PlanExecutor wrapping an UpdateStage.
Details
In order to support findAndModify, the UpdateStage and the DeleteStage will be extended as follows:
- A returnDeleted option will be added to DeleteRequest, with a default of false. Find and modify operations will set this option to true. A delete PlanExecutor with returnDeleted set will return PlanExecutor::ADVANCED and an owned copy of the deleted object every time that it commits a document delete.
- The option returnDocs will be added to UpdateRequest, replacing the existing storeResultDoc option. It will take one of three values: RETURN_NEW, RETURN_OLD, or RETURN_NONE.
- If RETURN_NEW, the PlanExecutor will return PlanExecutor::ADVANCED with a owned or unowned copy of each updated document's post-image. If the update results in an insert, it will return ADVANCED once and return the inserted document.
- If RETURN_OLD, the PlanExecutor will return PlanExecutor::ADVANCED with an owned copy of each updated document's pre-image. If the update results in an insert, it will return neither ADVANCED nor will it return a copy of the updated document.
- If RETURN_NONE, the behavior will remain as is. Namely, the PlanExecutor will never return ADVANCED.
Explain
This change should allow for a sane implementation of CmdFindAndModify::explain(). The explain will return the UPDATE or DELETE plan tree being used to execute the operation.
Further notes
- findAndModify will have the same behavior under concurrency as regular updates and deletes. It will take a MODE_IX lock and will use a YIELD_AUTO plan.
- If upsert is set to true, this will simply be passed through by setting the upsert flag on the UpdateRequest.
- findAndModify will continue to require its own handling for WriteConflictException retry and for collection creation on upsert into an empty collection.
- Find and modify will no longer depend on helpers such as deleteObjects() or mongo::update().
- This will probably involve a rewrite or at least clean up the parsing of the command BSON.
- is duplicated by
-
SERVER-6865 positional operator projection does not work with find and modify
- Closed
-
SERVER-23171 Bad projection with findAndModify()
- Closed
-
SERVER-12414 Projecting {$meta: textScore} does not work in findAndModify
- Closed
-
SERVER-15128 Explain command for explaining findAndModify
- Closed
- is related to
-
SERVER-15715 find_and_modify appears to be taking a DB_X lock
- Closed
- related to
-
SERVER-16071 The nscanned and nscannedObjects is not correct for findAndModify
- Closed
-
SERVER-16469 findAndModify with sort exceeds internal sort memory limit, silently fails
- Closed
-
SERVER-18054 Crash when running findAndModify against non-existent collection
- Closed
-
SERVER-19957 findAndModify with remove=true doesn't retry deleting document on WCE
- Closed
-
SERVER-24462 findAndModify does not update Top
- Closed