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.
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)
Thanks @AbdelrahmanHafez, forgot to include the error, will do next time 馃憤