Introduce populate ordered option for populating in series rather than in parallel #15231
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Currently Mongoose executes all populate queries in parallel, which is problematic for transactions. Re: #15091, #15100, etc., MongoDB server does not support multiple operations in parallel within a single transaction. With this PR, you can populate with
ordered: true
as followsFix #15210
A couple of noteworthy caveats:
populate()
is always an array, becauseordered
is the only option we have that configures the top-levelpopulate()
call, as opposed to the individual_populatePaths()
calls. That makes it somewhat tricky to passordered
as a top-level option: assigningordered
as a property on thepaths
array is a bit error prone because it is easy to copy the array and loseordered
. So we made it so that we treat top-level populate asordered
if any of the populatepaths
are set toordered
, which seems like a reasonable workaround.path
option. This PR allows passing an array of strings aspath
.This PR may be helpful for #13985, but I need to double check.
Examples