🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

mongo-softdelete

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongo-softdelete

Mongo wrapper that supports soft delete on collections

latest
Source
npmnpm
Version
2.0.1
Version published
Maintainers
1
Created
Source

mongo-softdelete

Wrapper for a mongo collection that soft delete documents. Soft delete documents is not remove from the collection but instead the property _deleted has been added to the document. Queries executed from the wrapped collection will ignore soft deleted documents.

A soft deleted document will have the property _deleted set to a time stamp.

{
  _deleted: new Date(),
  data: ...
}

The following methods are not supported:

  • distinct
  • createIndex
  • ensureIndex
  • mapReduce
  • group
  • geoNear
  • geoHaystackSearch
  • aggregate

Usage:

var mongoSsoftDelete = require('mongo-softdelete');

mongodb.Db.connect(connection, function(err, db){
  if(err) throw err;
  
  database.collection('softDeleteCollection', function (err, col) {
    if(err) throw err;
    
    var softDeleteCollection = mongoSsoftDelete(col);
    
    softDeleteCollection.insert({a: 1}, function(err, doc) {
      if(err) throw err;
      
      softDeleteCollection.remove(function(err, doc) {
        if(err) throw err;
      
        softDeleteCollection.findOne({a: 1}, function (err, doc) {
          if(err) throw err;
      
          // does not return the soft deleted document - but it still exist in the collection
          console.log(doc);
        });
      })
    })
  });
});

FAQs

Package last updated on 30 Jan 2019

Did you know?

Socket

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.

Install

Related posts