Skip to content

Instantly share code, notes, and snippets.

@hyperparabolic
Created January 6, 2020 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyperparabolic/ac1ae6032f283b64c7768b156f542e11 to your computer and use it in GitHub Desktop.
Save hyperparabolic/ac1ae6032f283b64c7768b156f542e11 to your computer and use it in GitHub Desktop.
Reproduce: Mongoose slice followed by any operation that calls `cast` during the following operation results in an error
const Mongoose = require('mongoose');
const { Schema } = Mongoose;
const xSchema = new Schema({
a: [String],
});
const X = Mongoose.model('X', xSchema);
const x = new X({
a: ['c'],
});
// x.a[Symbol(mongoose#Array#_schema)] is an object with caster property
// fine
x.a.unshift('b');
const a = x.a.slice();
// a[Symbol(mongoose#Array#_schema)] is undefined
// not fine
a.unshift('a');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment