mongoose-soft

0.5.2 • Public • Published

mongoose-soft

Build Status Coverage Status

Mongoose soft delete. I created it because other packages that I tested didn't work properly.

How it works

Model.remove() was extended to set deleted: true without real removing. To methods find, findOne, update, findOneAndUpdate, findOneAndRemove were added middleware to show only data without deleted: true.

Configuration

const mongoose = require('mongoose');
const softDelete = require('mongoose-soft');
 
const db = mongoose.createConnection('mongodb://localhost:27017/your-db');
const schema = new mongoose.Schema({ text: String });
 
schema.plugin(softDelete);
db.model('posts', schema);

Find deleted data

If you want to see deleted data pass deleted: true in the query object. If you want to see all data pass deleted: { $in: [null, true, false] }.

Package Sidebar

Install

npm i mongoose-soft

Weekly Downloads

1

Version

0.5.2

License

ISC

Last publish

Collaborators

  • kozzztya