Implementing a Mongoose Plugin for Soft Delete Array doc and root doc Filtering
I am developing a Mongoose plugin to handle soft deletion and filtering of soft-deleted items using find() in a MongoDB database. The plugin needs to:
- Automatically filter out soft-deleted documents and nested array items in find() queries.
- Provide a method to perform soft deletion on both top-level documents and nested array items.
- Allow the option to include soft-deleted items in queries when needed.
My main challenges are:
- Ensuring the pre-find hook efficiently filters both top-level and nested soft-deleted items.
- Implementing a flexible soft delete method that works for various document structures.
- Handling the option to show soft-deleted items without complicating the query process.
I am particularly interested in:
- Handling of nested documents and arrays.
Any guidance or example patterns would be greatly appreciated!
Data :
{
"_id": {
"$oid": "66c883a5e6ddbf5f720ae1b6"
},
"name": "Some Name",
"email": "[email protected]",
"age": 48,
"nestedArr": [
{
"id": 7032086,
"value": "apple0",
"isDeleted": false
},
{
"id": 4086837,
"value": "apple0",
"isDeleted": true
},
{
"id": 6683277,
"value": "apple0",
"isDeleted": false
},
{
"id": 2870389,
"value": "apple0",
"isDeleted": true
}
],
"isDeleted": true,
}