There is a collection with documents in the database,
we created Schema and created Model.
At the same time, not all fields of documents are described in the schema
i.e. some documents have fields not described in the schema.
Now we execute the model.deleteMany({x:}) where “x” is not in the schema
This call removes ALL documents in the collection!
This behavior was not in version 5
I suspect this is another consequence of Mongoose 6 changing the strictQuery behaviour so query filter properties that are not in the schema will now be filtered out by default .
Mongoose is an open source community project, so the best channel to search or create Mongoose bug reports is the GitHub issue queue: Issues · Automattic/mongoose · GitHub.
@Stennie_X
I only recently work with mongoose, and when I came across this error - I was very surprised by this behavior, and began to look for where to report it. I found this community , but after two days I did not find the reaction, and further search led to GitHub issue.
Now the situation is clear to me, I still think that such behavior is very dangerous, and at least it should have been written about separately in Migrating to Mongoose 6 document.
Regards,
Vadim