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
I have searched existing issues to ensure the bug has not already been reported
Mongoose version
7.0.1
Node.js version
18.13.0
MongoDB server version
6.0.4
Typescript version (if applicable)
4.9.5
Description
On the method validateSync, you can provide the paths to validate, if you provide a path that corresponds to an array, and the item's values of that array are wrong, it won't throw an error, because you need to provide in the path the index of the value you want to validate.
Steps to Reproduce
Create a model like this:
import { model, Schema } from "mongoose";
const schema = new Schema({
permissions: [{type: String, enum: ['users', 'anotherPermission']}]
});
const Model = model('Model', UserSchema);
Then create an object with invalid values on permissions:
const a = {
permissions: ["avocado"]
}
Then validate the object with the model you previously created in these two different ways and see the errors:
In the first one, and the second one, you should be able to get an error, and in the third one, you don't get any error.
Expected Behavior
It is clear that there is an error in the Object that we created previously, but you only are available to get in two of three scenarios, but for me, we should get the error in the three scenarios, when we specify a path that we want to validate, the method should be able to validate all the nested object in that path.
The text was updated successfully, but these errors were encountered:
…path to `validate()` and `validateSync()` `pathsToValidate` param
Fix#13159
vkarpov15
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
labels
Mar 13, 2023
Prerequisites
Mongoose version
7.0.1
Node.js version
18.13.0
MongoDB server version
6.0.4
Typescript version (if applicable)
4.9.5
Description
On the method validateSync, you can provide the paths to validate, if you provide a path that corresponds to an array, and the item's values of that array are wrong, it won't throw an error, because you need to provide in the path the index of the value you want to validate.
Steps to Reproduce
Create a model like this:
Then create an object with invalid values on permissions:
Then validate the object with the model you previously created in these two different ways and see the errors:
In the first one, and the second one, you should be able to get an error, and in the third one, you don't get any error.
Expected Behavior
It is clear that there is an error in the Object that we created previously, but you only are available to get in two of three scenarios, but for me, we should get the error in the three scenarios, when we specify a path that we want to validate, the method should be able to validate all the nested object in that path.
The text was updated successfully, but these errors were encountered: