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 = ;const softDelete = ; const db = mongoose;const schema = text: String ; schema;db;
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] }
.