Skip to content

Latest commit

 

History

History
30 lines (20 loc) · 1.09 KB

README.md

File metadata and controls

30 lines (20 loc) · 1.09 KB

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