
Security News
Node.js Homepage Adds Paid Support Link, Prompting Contributor Pushback
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
delete-soft-mongoose
Advanced tools
This Mongoose plugin provides soft deletion functionality for MongoDB, allowing you to mark documents as deleted without physically removing them from the database.
npm install delete-soft-mongoose
yarn add delete-soft-mongoose
Import the plugin in your Mongoose schema file.
const softDeletePlugin = require('delete-soft-mongoose');
Apply the plugin.
Apply the plugin To your schema:
const YourSchema = new mongoose.Schema({
// ... your schema fields
});
YourSchema.plugin(softDeletePlugin);
Apply the plugin globally.
const mongoose = require("mongoose");
const softDeletePlugin = require("delete-soft-mongoose");
mongoose.plugin(softDeletePlugin)
Your schema will now have a deleted
field with status
, at
, and by
properties.
const exampleDocument = new YourModel({
// ... your document fields
});
// Soft delete document
await exampleDocument.softDelete();
softDelete(query, options, deletedBy)
Soft deletes documents based on the provided query.
query
: The query to find documents to soft-delete.options
: Options to pass to the save
method.deletedBy
: The user or entity performing the soft deletion.Returns an object with the count of soft-deleted documents.
softDeleteById(id, deletedBy)
Soft deletes a document by its ID.
id
: The ID of the document to soft-delete.deletedBy
: The user or entity performing the soft deletion.Returns an object with the count of soft-deleted documents and a message.
restore(query)
Restores soft-deleted documents based on the provided query.
query
: The query to find documents to restore.Returns an object with the count of restored documents.
restoreById(id)
Restores a soft-deleted document by its ID.
id
: The ID of the document to restore.Returns an object with the count of restored documents and a message.
findAll(query)
Finds all documents that are not marked as deleted.
query
: Additional query parameters.Returns an array of documents.
findDeleted(query)
Finds all documents that are marked as deleted.
query
: Additional query parameters.Returns an array of documents.
This project is licensed under the MIT License - see the LICENSE.md file for details.
Simply fork and send pull request.
Please use the issue tracker to report any issues.
..........................
FAQs
soft delete for mongoose, mongodb javascript
The npm package delete-soft-mongoose receives a total of 3 weekly downloads. As such, delete-soft-mongoose popularity was classified as not popular.
We found that delete-soft-mongoose demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.
Research
Security News
The Socket Research Team investigates a malicious Python typosquat of a popular password library that forces Windows shutdowns when input is incorrect.