-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option strict
is used before Schema and global level strictQuery
#12508
Comments
const strictQuery = 'strictQuery' in options ?
options.strictQuery :
'strict' in options ?
options.strict :
'strict' in schema._userProvidedOptions ? schema._userProvidedOptions.strict :
schema.options.strictQuery; It should be like that imo ( strictQuery always as the priority then strict ) strict in options and strictQuery is not set then strictQuery to strict |
strict
is used before Schema and global level strictQuery
Updated title to match issue, because function-level |
const mongoose = require("mongoose");
mongoose.set("debug", true);
mongoose.set("strictQuery", false);
const options = {
strict: "throw",
strictQuery: false
};
const eventSchema = new mongoose.Schema({ time: Date }, options);
const Event = mongoose.model("Event", eventSchema);
async function run() {
await mongoose.connect("mongodb://localhost:27017");
// 1. Not working
const res = await Event.find({ url: "google.com" });
}
run(); |
fix(cast): make schema-level strictQuery override schema-level strict for query filters
Prerequisites
Mongoose version
6.63
Node.js version
16
MongoDB server version
4.9.1
Description
Hello, when strict is set to throw, I cannot set strictQuery to anything else then throw.
On docs, it says
However, strictQuery is tied to strict by default. This means that, by default, Mongoose will filter out query filter properties that are not in the schema.
I cannot untied strictQuery and Query globally on in shcema option, I have to use QueryOption.
This is the expected Behavior ? the doc is unclear.
Steps to Reproduce
Expected Behavior
Should be able to set strictQuery to anything else then throw in schema option or globally not only in query opt
The text was updated successfully, but these errors were encountered: