You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Even though strict is set to throw for all schemas, it does not throw for inner _id properties. The following code fails on 5.4.9:
#!/usr/bin/env node
(asyncfunction(){constmongoose=require('mongoose');mongoose.plugin((schema)=>{schema.options.versionKey=false;schema.options.minimize=false;schema.options.strict='throw';schema.options.strictQuery='throw';});mongoose.connect('mongodb://localhost:27017/test',{useNewUrlParser: true});constschema=newmongoose.Schema({inner: {type: newmongoose.Schema({_id: false,// _id is disabled heresomething: {type: Boolean,required: true}}),require: true}});constModel=mongoose.model('test',schema);constinstance=newModel({inner: {_id: mongoose.Types.ObjectId(),// property not allowed but it will validatesomething: true}});awaitinstance.save();// should fail but does notconsole.log('This message should not appear (but it will)');})();
The text was updated successfully, but these errors were encountered:
Setting _id: false in the schema path definition as opposed to as a schema option is an odd meme that's managed to find its way into a lot of codebases despite never being documented or fully supported. We'll make it work for this case 👍
* https://github.com/Automattic/mongoose: (41 commits)
fix(query): copy mongoose options when using `Query#merge()`
test(query): repro Automattic#1790
chore: remove unnecessary references to old mongoose versions
fix(deps): update dependency ms to v2.1.1
fix(timestamps): don't call createdAt getters when setting updatedAt on new doc
chore: now working on 5.4.12
test(timestamps): repro Automattic#7496
chore: release 5.4.11
docs: add views guru as sponsor
refactor: use consolidated `isPOJO()` function instead of constructor checks
fix(schema): handle `_id: false` in schema paths as a shortcut for setting the `_id` option to `false`
test(schema): repro Automattic#7480
Documentation: Document.prototype.validateSync returns ValidationError
gitignore correct syntax
style: fix lint
fix(update): handle $addToSet and $push with ObjectIds and castNonArrays=false
test(update): repro Automattic#7479
docs(model): document `session` option to `save()`
chore: bump lodash dev dep re: security
chore: now working on 5.4.11
...
Even though
strict
is set tothrow
for all schemas, it does not throw for inner_id
properties. The following code fails on 5.4.9:The text was updated successfully, but these errors were encountered: