Mongoose 6 introduced many changes, and the most important change was the strict and strictQuery for the search queries, they are equal to true by default.
https://mongoosejs.com/docs/migrating_to_6.html#strictquery-is-removed-and-replaced-by-strict
I have a schema like this:
const mySchema = new mongoose.Schema({
name: String
})
And I have a document like the following in the database:
{
name: "Murat",
_archived: true
}
as You can see, the field _archived does not exist in the schema.
Now If I wanted to:
const archivedDocs = await myModel.find({ _archived: true })
I can't because of the new update.
Mongoose says that if you wanted to perform this search query, you can add the strictQuery option to your schema and set it to true.
However, I don't want to do that, because this will have an effect everywhere. I only want to allow this one find() line of code to pass this checking.
Is there something in mongoose that I can do like:
const archivedDocs = await myModel.find({ _archived: true }, { strictQuery: false })
??