Update statements can now appear in both the bulkWrite command (which is being adopted by drivers in DRIVERS-716) as well as in the update command. Individual update statements are more or less equivalent in both contexts, but they are currently implemented with separate code paths. (In the future, we may want to see if we can share more between code between the two.)
Both paths execute updates by creating a classic engine PlanExecutor (a PlanExecutorImpl) and then iterating it in order to execute the update. However, the code to do so is not shared. The update command is implemented in terms of PlanExecutorImpl::executeUpdate() whereas the bulkWrite version is implemented in terms of a helper called advanceExecutor(). I imagine that the reason for this discrepancy is that bulkWrite supports findAndModify-style statements in which a deleted or updated document can be returned.
That said, I don't see a good reason for the two code paths to use separate implementations of iterating the PlanExecutor. Indeed, this caused us to have to duplicate the code for fixing related ticket SERVER-91465. The work for this ticket is to see if PlanExecutorImpl::executeUpdate() and advanceExecutor() can be consolidated, removing the duplication introduced by SERVER-91465 in the process.
- is related to
-
SERVER-91465 Don't Return StaleConfig for UpdateMany on Unsplittable Collections
- Closed