Created
January 6, 2020 22:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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