Mongoose Soft Delete Plugin
Mongoose plugin that enables soft deletion of Models/Documents.
This plugin is based on the work of Yi.
In the original plugin, models were deleted with a date reference only. This version takes that and uses a Boolean flag to to mark models deleted/restored. Adds
deletedAt field to record when a document was deleted. Additionally, it removes a lot of overhead from the original code and doesn't use Coffeescript.
This plugin is licensed under the MIT license and can ve viewed in the LICENSE file.
Install using npm
npm install mongoose-softdelete --save
IMPORTANT: You need to have MongoDB running to run tests
const mongoose =Schema = mongooseSchemasoft_delete = ;const TestSchema =somefield: type: String default: 'Hello World!';TestSchema;mongoose;
const Test = mongoose;const test = ;test;test;// chainable query method// defaults to true unless specifiedTest;
;;;TestSchema.pluginsoftdelete;;;test1.softdelete;// chainable query method// defaults to true unless specifiedTest.find as unknown as ISoftDeletedDocumentQuery.isDeletedfalse
Built with love in Dhaka, Bangladesh by Riyadh Al Nur