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

Error when calling unshift() after map() #9012

Closed
philippejer opened this issue May 16, 2020 · 2 comments · Fixed by #9013
Closed

Error when calling unshift() after map() #9012

philippejer opened this issue May 16, 2020 · 2 comments · Fixed by #9013
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@philippejer
Copy link
Contributor

This is almost the same issue as #8399 (root cause seems to be #8356).

Here is a repro:

const MyModel = db.model('Test', Schema({
  myArray: [{ name: String }]
}));

const doc = new MyModel({
  myArray: [{ name: 'b' }, { name: 'c' }]
});
let myArray = doc.myArray;

myArray = myArray.map(val => ({ name: `${val.name} mapped` }));

myArray.unshift({ name: 'a inserted' });

assert.deepEqual(myArray.map(v => v.name), [
  'a inserted',
  'b mapped',
  'c mapped'
]);

I'll create a PR in a minute for this issue.

@AbdelrahmanHafez
Copy link
Collaborator

Output for script above

TypeError: Cannot read property 'applySetters' of null
    at CoreDocumentArray.unshift (mongoose\lib\types\core_array.js:893:38)
    at Object.<anonymous> (mongoose\test.js:17:9)

@philippejer
Copy link
Contributor Author

Thanks @AbdelrahmanHafez, forgot to include the error, will do next time 👍

@vkarpov15 vkarpov15 added this to the 5.9.15 milestone May 18, 2020
@vkarpov15 vkarpov15 added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label May 18, 2020
vkarpov15 added a commit that referenced this issue May 18, 2020
fix(documentarray): make sure you can call `unshift()` after `map()`
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.

3 participants