mongoose-soft
v0.5.2
Published
Mongoose soft delete
Downloads
10
Readme
mongoose-soft
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] }
.