{"id":24941395,"url":"https://github.com/muhammadrifat/soft-deleting-mongoose","last_synced_at":"2026-04-29T12:35:52.241Z","repository":{"id":167090950,"uuid":"642534334","full_name":"MuhammadRifat/soft-deleting-mongoose","owner":"MuhammadRifat","description":"This is the simple, light-weight soft deleting package for Mongodb using mongoose ODM.","archived":false,"fork":false,"pushed_at":"2023-07-26T17:52:38.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T13:07:26.904Z","etag":null,"topics":["mongodb","mongoose","npm-package","soft-delete"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/soft-deleting-mongoose","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MuhammadRifat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-18T19:40:47.000Z","updated_at":"2023-05-19T17:56:44.000Z","dependencies_parsed_at":"2024-10-20T15:39:42.371Z","dependency_job_id":null,"html_url":"https://github.com/MuhammadRifat/soft-deleting-mongoose","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"08d3f299866a318501f7ac9a03aab7bd890d88af"},"previous_names":["muhammadrifat/soft-deleting-mongoose"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuhammadRifat%2Fsoft-deleting-mongoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuhammadRifat%2Fsoft-deleting-mongoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuhammadRifat%2Fsoft-deleting-mongoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuhammadRifat%2Fsoft-deleting-mongoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MuhammadRifat","download_url":"https://codeload.github.com/MuhammadRifat/soft-deleting-mongoose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246072224,"owners_count":20719275,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mongodb","mongoose","npm-package","soft-delete"],"created_at":"2025-02-02T18:22:34.925Z","updated_at":"2026-04-29T12:35:52.197Z","avatar_url":"https://github.com/MuhammadRifat.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# soft-deleting-mongoose\r\n\r\nThis is a simple, easy-to-understand soft deleting package for MongoDB using Mongoose ODM. This package gives you all functionality to soft delete any Mongodb document. So let's start soft deleting...\r\n\r\n## Installation\r\n`npm install soft-deleting-mongoose`\r\n\r\n## Usage\r\n\r\n#### Defining schema\r\n\r\nFirstly import **MongooseSchema** and create a schema.\r\n\r\n```js\r\nconst userSchema = new MongooseSchema({\r\n    name: {\r\n        type: String,\r\n        required: true\r\n    },\r\n    email: {\r\n        type: String,\r\n        required: true,\r\n    },\r\n    role: {\r\n        type: String,\r\n        default: \"user\"\r\n    },\r\n    password: String\r\n});\r\n```\r\n\r\n#### Creating a model\r\n\r\n```js\r\nconst User = mongoose.model('User', userSchema);\r\n```\r\n\r\n#### Delete a user by using soft deleting\r\n\r\n```js\r\napp.delete(\"/user/:_id\", async (req, res, next) =\u003e {\r\n    try {\r\n        const _id = req.params._id;\r\n        const user = await User.softDeleteById(_id);\r\n\r\n        return res.status(200).json({ success: true, data: user });\r\n    } catch (error) {\r\n        next(error);\r\n    }\r\n});\r\n```\r\n\r\n### Provided the following query helpers for soft deleting.\r\n\r\n- .notDeleted()\r\n- .onlyDeleted()\r\n- .withDeleted()\r\n\r\n### Provided the following static functions for soft deleting.\r\n\r\n- Model.softDelete(query)\r\n- Model.softDeleteById(_id)\r\n- Model.restoreById(_id)\r\n- Model.restore(query)\r\n- Model.restoreAll()\r\n- Model.forceDeleteById(_id)\r\n- Model.forceDelete(query)\r\n\r\n## Usage Example of query helpers\r\n\r\nIn the above, I have declared a model named **User**. Now I am giving examples using the **User** model.\r\n\r\n#### .notDeleted()\r\n- Get not deleted documents\r\n\r\n```js\r\nUser.find({}).notDeleted();\r\n```\r\n\r\n#### .onlyDeleted()\r\n- Get only deleted documents\r\n\r\n```js\r\nUser.find({}).onlyDeleted();\r\n```\r\n#### .withDeleted()\r\n- Get both types of documents (deleted + not deleted)\r\n\r\n```js\r\nUser.find({}).withDeleted();\r\n```\r\n\r\n## Usage Example of static functions\r\n\r\nIn the above, I have declared a model named **User**. Now I am giving examples using the **User** model.\r\n\r\n#### Model.softDelete(query)\r\n- Soft delete the matched documents by query\r\n\r\n```js\r\nUser.softDelete({ role: \"user\" });\r\n```\r\n\r\n#### Model.softDeleteById(_id)\r\n- Soft delete the document by _id\r\n\r\n```js\r\nconst _id = \"6405d153a208cbfd7b88b0c5\";\r\nUser.softDeleteById(_id);\r\n```\r\n\r\n#### Model.restoreById(_id)\r\n- Restore the deleted document by _id\r\n\r\n```js\r\nconst _id = \"6405d153a208cbfd7b88b0c5\";\r\nUser.restoreById(_id);\r\n```\r\n\r\n#### Model.restore(query)\r\n- Restore the matched deleted documents by query\r\n\r\n```js\r\nconst _id = \"6405d153a208cbfd7b88b0c5\";\r\nUser.restoreById(_id);\r\n```\r\n\r\n#### Model.restoreAll()\r\n- Restore all deleted documents\r\n\r\n```js\r\nUser.restoreAll();\r\n```\r\n\r\n#### Model.forceDeleteById(_id)\r\n- Permanently delete a document by _id\r\n\r\n```js\r\nconst _id = \"6405d153a208cbfd7b88b0c5\";\r\nUser.forceDeleteById(_id);\r\n```\r\n\r\n#### Model.forceDelete(query)\r\n- Permanently delete the matched documents by query\r\n\r\n```js\r\nUser.forceDeleteById({ role: \"sub-admin\" });\r\n```\r\n\r\n## Usage Example in TypeScript\r\n\r\n#### Creating a model\r\n\r\n```js\r\nconst User = mongoose.model\u003cIUserDoc, Model\u003cIUserDoc, IQueryHelpers\u003cIUserDoc\u003e\u003e\u003e('User', userSchema);\r\n```\r\n\r\nHeder, **IUserDoc** is the interface of user, **Model** is imported from mongoose, and **IQueryHelpers** is imported from **soft-deleting-mongoose** package.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuhammadrifat%2Fsoft-deleting-mongoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuhammadrifat%2Fsoft-deleting-mongoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuhammadrifat%2Fsoft-deleting-mongoose/lists"}