-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Labels
confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Description
I'm not sure if it's a bug or just a very surprising behavior, but here we go:
new mongoose.Schema({
arrayOfDocuments: {
type: [{
...
}],
validate: {
validator: v => _.uniqBy(_.map(v, '_id'), id => id.toString()).length === v.length,
message: 'Ids have to be unique.'
}
}
})Now let's run an update query on this model:
// validators are set to run on update
await SomeModel.findOneAndUpdate(
{_id: 'some object id'},
{$pull: {arrayOfDocuments: {_id: 'another object id'}}}
);The above validator will be run with {_id: 'another object id'} as an argument - which isn't an array. I don't think this is valid, it's trying to validate a subset of document properties by passing it to an array validator.
Metadata
Metadata
Assignees
Labels
confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.We've confirmed this is a bug in Mongoose and will fix it.