Installations
npm install soft-delete-plugin-mongoose
Releases
Unable to fetch releases
Developer
nour-karoui
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
20.2.0
NPM Version
9.6.6
Statistics
40 Stars
61 Commits
14 Forks
3 Watching
2 Branches
6 Contributors
Updated on 29 Jun 2024
Languages
TypeScript (97.09%)
JavaScript (2.91%)
Total Downloads
Cumulative downloads
Total Downloads
501,976
Last day
2.7%
413
Compared to previous day
Last week
13.2%
2,343
Compared to previous week
Last month
18.1%
9,144
Compared to previous month
Last year
-62%
96,554
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Dev Dependencies
5
Welcome to soft-delete-plugin-mongoose 👋
a mongoose plugin that allows you to soft delete documents and restore them in MongoDB (for JS & TS)
-
Soft delete your MongoDB documents and restore them
-
JS and TS
🏠 Homepage
Install
1npm install soft-delete-plugin-mongoose
How It Works
Javascript Version
1const mongoose = require('mongoose');
2const { softDeletePlugin } = require('soft-delete-plugin-mongoose');
3const Schema = mongoose.Schema;
4
5const TestSchema = new Schema({
6 name: String,
7 lastName: String
8});
9
10TestSchema.plugin(softDeletePlugin);
11const TestModel = mongoose.model("Test", TestSchema);
12
13const test = new TestModel({name: 'hello', lastName: "world"});
14
15/*** returns an object containing the number of softDeleted elements ***/
16/***
17 {deleted: number}
18***/
19/***
20 the argument options is optional
21***/
22const options = { validateBeforeSave: false };
23const deleted = await TestModel.softDelete({ _id: test._id, name: test.name }, options);
24/**
25 const deleted = await Test.softDelete({ _id: test._id, name: test.name }); is also valid
26**/
27
28/*** returns an object containing the number of restored elements ***/
29/***
30 {restored: number}
31***/
32const restored = await TestModel.restore({ _id: test._id, name: test.name });
33
34/*** returns all deleted elements ***/
35const deletedElements = await TestModel.findDeleted();
36
37/*** returns all available elements (not deleted) ***/
38const availableElements = await TestModel.find();
39
40/*** counts all available elements (not deleted) ***/
41const countAvailable = await TestModel.count();
42
43/*** findById returns the document whether deleted or not ***/
Typescript Version
1import * as mongoose from 'mongoose'; 2import { softDeletePlugin, SoftDeleteModel } from 'soft-delete-plugin-mongoose'; 3 4interface Test extends mongoose.Document { 5 name: string; 6 lastName: string; 7} 8 9const TestSchema = new mongoose.Schema({ 10 name: String, 11 lastName: String 12}); 13TestSchema.plugin(softDeletePlugin); 14// two different ways of implementing model depending on technology used 15// 1st way 16const testModel = mongoose.model<Test, SoftDeleteModel<Test>>('Test', TestSchema); 17 18//2nd way (nestjs way) 19constructor(@InjectModel('Test') private readonly testModel: SoftDeleteModel<Test>) {} 20 21const test = await new this.testModel({name: 'hello', lastName: 'world'}); 22 23/*** returns an object containing the number of softDeleted elements ***/ 24/*** 25 {deleted: number} 26***/ 27/*** 28 the argument options is optional 29***/ 30const options = { validateBeforeSave: false }; 31const deleted = await this.testModel.softDelete({ _id: test._id, name: test.name }, options); 32/** 33 const deleted = await Test.softDelete({ _id: test._id, name: test.name }); is also valid 34**/ 35 36/*** returns an object containing the number of restored elements ***/ 37/*** 38 {restored: number} 39***/ 40const restored = await this.testModel.restore({ _id: test._id, name: test.name }); 41 42/*** returns all deleted elements ***/ 43const deletedElements = await this.testModel.findDeleted(); 44 45/*** returns all available elements (not deleted) ***/ 46const availableElements = await this.testModel.find(); 47 48/*** counts all available elements (not deleted) ***/ 49const countAvailable = await this.test.count(); 50 51/*** findById returns the document whether deleted or not ***/
Author
👤 Nour
- Github: @nour-karoui
- LinkedIn: @nourkaroui
🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.
Show your support
Give a STAR if this project helped you!
📝 License
This README was generated with by readme-md-generator
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 9/18 approved changesets -- score normalized to 5
Reason
7 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 22 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to soft-delete-plugin-mongoose
mongoose-delete
Mongoose soft delete plugin
@mahdad/soft-delete-plugin-mongoose
a mongoose plugin that allows you to soft delete documents and restore them (for JS & TS)
soft-delete-mongoose-plugin
mongoose soft delete plugin
prisma-extension-soft-delete
Prisma extension for soft deleting records