Closed
Description
Do you want to request a feature or report a bug?
Bug in the latest mongoose version (5.2.1)
What is the current behavior?
Schemas ignore default: null
for arrays, empty array is created instead.
const schema = new mongoose.Schema({
arrayThatShouldBeNull: {
type: [String],
default: null,
required: false
},
arrayThatShouldContainTwoEntries: {
type: [String],
default: ['asd', '123'],
required: false
}
}, {
minimize: false // not sure if relevant
});
const Model = mongoose.model('test', schema);
const instance = new Model();
expect(instance.arrayThatShouldBeNull).to.be.null; // fails
expect(instance.arrayThatShouldContainTwoEntries).to.deep.equal(['asd', '123']); // passes
What is the expected behavior?
instance.arrayThatShouldBeNull
should be set to null, but instead an empty array is created
Activity