fix(populate): allow deselecting discriminator key when populating #14155
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 #3230
Re: #13760
Re: #13679
Summary
Right now, populating with
__t: 0
in projection throws a "Cannot do inclusion on field prop in exclusion projection", whereas deselecting projection works fine outside ofpopulate()
. The issue looks to be an ordering issue: Mongoose isn't correctly handling__t: 0
as the first property in theselect
object, and withpopulate()
Mongoose was reversing key order, so{ name: 1, __t: 0 }
was ending up as{ __t: 0, name: 1 }
because ofutils.object.shallowCopy
.Both issues are fixed: Mongoose now handles
__t: 0
as first property in select object (utils.object.shallowCopy()
was removed, no longer necessary with spread operator), andpopulate()
with{ __t: 0 }
now works as expected 👍Examples