fix(document): allow calling push()
with different $position
arguments
#14254
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.
Fix #14244
Re: #4322
Summary
When we originally implemented
push()
with$position
in #4322, we made it so that callingpush()
with different$position
arguments would throw a sync error. This decision is not completely unreasonable because the MongoDB server doesn't support$push
with different$position
arguments. However, this decision is inconsistent with the rest of the array API: as a general rule, Mongoose arrays revert to just making the operation a$set
on the entire array when Mongoose can't represent the user's desired update using atomic operators. With this PR, we will convert from atomic update to$set
on the whole array if the user callspush()
with multiple different$position
arguments.With this change, a modified version of the repro script from #14244 prints the following:
Modified version as follows:
Examples