Replies: 1 comment
-
This behavior is configured by the If you want to disable this behavior in Mongoose 6, just do the following. Or upgrade to Mongoose 7.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi community !
I recently encountered a situation where the use of deleteMany in Mongoose could lead to unintended deletions when a field specified in the query is not found in the schema.
Consider the following scenario:
If the field user_id does not exist in the schema, the query seems to match all documents in the collection, resulting in the deletion of all documents, which could be critical.
I understand that Mongoose operates based on the queries it receives, but I wanted to bring attention to the potential risk this behavior poses in terms of unintended data loss. This situation might be common among developers, especially those transitioning between different projects with different schema conventions.
I would like to open a discussion on whether there could be a way to handle such cases more gracefully, perhaps by throwing a warning or error when a field in the query is not found in the schema, or by providing a mechanism to check the validity of the fields before performing the delete operation.
Has anyone else experienced similar concerns? What are your thoughts on potential improvements in this area?
Beta Was this translation helpful? Give feedback.
All reactions