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

Cannot read property 'filter' of undefined #8128

Closed
sibelius opened this issue Sep 4, 2019 · 6 comments · Fixed by #8130
Closed

Cannot read property 'filter' of undefined #8128

sibelius opened this issue Sep 4, 2019 · 6 comments · Fixed by #8130
Labels
needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
Milestone

Comments

@sibelius
Copy link
Contributor

sibelius commented Sep 4, 2019

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

What is the current behavior?
it is breaking with the following error:

TypeError: Cannot read property 'filter' of undefined

      at node_modules/mongoose/lib/model.js:3251:32
      at parallelLimit (node_modules/mongoose/lib/helpers/parallelLimit.js:15:12)
      at Function.Object.<anonymous>.Model.$__insertMany (node_modules/mongoose/lib/model.js:3245:3)
      at process.nextTick (node_modules/kareem/index.js:369:33)

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

Everything worked well on 5.6.11 but it broke on 5.6.12

What is the expected behavior?
it should not break

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose: 5.6.12
node: 10.15.0
mongo: v4.0.5

@nadr0
Copy link

nadr0 commented Sep 4, 2019

Happened to me too. I rolled out the version with 5.6.12 and it reported the same error. I have to roll back to 5.6.11 and things are back to normal.

@vkarpov15 vkarpov15 added this to the 5.6.13 milestone Sep 4, 2019
@vkarpov15 vkarpov15 added the needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue label Sep 4, 2019
@vkarpov15
Copy link
Collaborator

@sibelius not a very helpful bug report - please provide code samples next time. Stack traces are typically not very helpful 👎

@sibelius
Copy link
Contributor Author

sibelius commented Sep 4, 2019

the error happens when you are saving many documents at once

the error is here

https://github.com/Automattic/mongoose/blob/master/lib/model.js#L3251

const docAttributes = docs.filter(function(doc) {
return doc != null;
});

docs is null in parallelLimit

maybe a regression from here

03dfc6a

@sibelius
Copy link
Contributor Author

sibelius commented Sep 4, 2019

this could be the cause of the bug

03dfc6a#diff-af13acd1e8d4818a7336e3dd68eb5efbR15

if fns.length === 0), it won't have either error nor docs

@nadr0
Copy link

nadr0 commented Sep 4, 2019

@vkarpov15

I cannot share my exact snippet of code that failed but it failed in this way.

// inside some async function ...
try {
  const arr = [];
  const result = await myModel.insertMany(arr);
} catch (e) {
  console.log(e);
}

I tried to do insertMany (https://mongoosejs.com/docs/api.html#model_Model.insertMany) with an empty array and I got the same error @sibelius got.

@vkarpov15
Copy link
Collaborator

Looks like @sibelius fixed this in his latest #8130. @nadr0 please upgrade to mongoose 5.6.13 for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants