npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

delete-soft-mongoose

v1.0.10

Published

soft delete for mongoose, mongodb javascript

Downloads

52

Readme

Mongoose Soft Delete Plugin

This Mongoose plugin provides soft deletion functionality for MongoDB, allowing you to mark documents as deleted without physically removing them from the database.

Installation

npm install delete-soft-mongoose
yarn add delete-soft-mongoose

Usage

  1. Import the plugin in your Mongoose schema file.

    const softDeletePlugin = require('delete-soft-mongoose');
  2. 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)
  3. 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();

Methods

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.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments

  • Inspired by the need for soft deletion in MongoDB.

Contributing

Simply fork and send pull request.

Issues

Please use the issue tracker to report any issues.

Authors

  • Smile Pant

Acknowledgments

..........................