Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate with retainNullValues enabled & omitting _id throws Cannot read property '$__setValue' of null #9336

Closed
FelixRe0 opened this issue Aug 17, 2020 · 0 comments · Fixed by #9337
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@FelixRe0
Copy link
Contributor

FelixRe0 commented Aug 17, 2020

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Using populate + omitting _id results in the following error if the populated document does not exist and retainNullValues is set to true:

TypeError: Cannot read property '$__setValue' of null
   at maybeRemoveId (\node_modules\mongoose\lib\helpers\populate\assignVals.js:237:23)
   at valueFilter (\node_modules\mongoose\lib\helpers\populate\assignVals.js:193:7)
   at setValue (\node_modules\mongoose\lib\helpers\populate\assignVals.js:67:12)

If the current behavior is a bug, please provide the steps to reproduce.

 const options = {
     model: 'Model',
     select: 'title -_id',
     options: { retainNullValues: true },
   }
  let user = await User.findById(_id , 'arrayOfObjectIds').populate({ options, path: 'arrayOfObjectIds' })

What is the expected behavior?

Returning array with populated document/null

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

Node v12.13.1
Mongoose ^5.10.0
MongoDB v4.2.8

I suspect that subdoc should be checked for value null in maybeRemoveId in assignVals.js

FelixRe0 added a commit to FelixRe0/mongoose that referenced this issue Aug 17, 2020
@AbdelrahmanHafez AbdelrahmanHafez added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Aug 17, 2020
@AbdelrahmanHafez AbdelrahmanHafez added this to the 5.10.1 milestone Aug 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants