0.5.2 • Published 7 years ago

mongoose-soft v0.5.2

Weekly downloads
7
License
ISC
Repository
github
Last release
7 years ago

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] }.