Gathering detailed insights and metrics for soft-delete-plugin-mongoose
Gathering detailed insights and metrics for soft-delete-plugin-mongoose
Gathering detailed insights and metrics for soft-delete-plugin-mongoose
Gathering detailed insights and metrics for 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
npm install soft-delete-plugin-mongoose
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
40 Stars
61 Commits
14 Forks
3 Watching
2 Branches
6 Contributors
Updated on 29 Jun 2024
TypeScript (97.09%)
JavaScript (2.91%)
Cumulative downloads
Total Downloads
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
1
5
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
1npm install soft-delete-plugin-mongoose
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 ***/
👤 Nour
Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.
Give a STAR if this project helped you!
This README was generated with by readme-md-generator
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 9/18 approved changesets -- score normalized to 5
Reason
7 existing vulnerabilities detected
Details
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
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
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 More