-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
has repro scriptThere is a repro script, the Mongoose devs need to confirm that it reproduces the issueThere is a repro script, the Mongoose devs need to confirm that it reproduces the issue
Milestone
Description
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When I set strict to 'throw', it works good on create() and update(). While when I try to set a inexist property to a model and call save(), it doesn't throw a StrictModeError but just drop the property.
If the current behavior is a bug, please provide the steps to reproduce.
Test case:
test('save() an inexistent property', async function () {
const schema = new mongoose.Schema({
name: String,
year_of_birth: { type: Number, immutable: true }
}, { strict: 'throw' });
const Person = mongoose.model('Person', schema);
const Joe = await Person.create({ name: 'Joe', year_of_birth: 2001 });
const id = Joe.id;
// Ok
await assert.isRejected(Person.create({ name: 'Joe', inexistence: 'something' }));
// Ok
await assert.isRejected(Person.findByIdAndUpdate(id, { inexistence: 'something' }));
// Doesn't throw error
Joe.inexistence = 'something';
await assert.isRejected(Joe.save());
})
What is the expected behavior?
It should throw a StrictModeError when using save().
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js 10.16.3
Mongoose 5.6.11
MongoDB 3.2.7
Metadata
Metadata
Assignees
Labels
has repro scriptThere is a repro script, the Mongoose devs need to confirm that it reproduces the issueThere is a repro script, the Mongoose devs need to confirm that it reproduces the issue