Comm Work - Magic Punch Code
Brought to you by:
finalfantasy
| File | Date | Author | Commit |
|---|---|---|---|
| lib | 2016-02-21 |
|
[45cc08] Initial commit |
| test | 2016-02-21 |
|
[45cc08] Initial commit |
| .gitignore | 2016-02-21 |
|
[45cc08] Initial commit |
| .jshintrc | 2016-02-21 |
|
[45cc08] Initial commit |
| README.md | 2019-06-20 |
|
[4f4703] Update README.md |
| index.js | 2016-02-21 |
|
[45cc08] Initial commit |
| package.json | 2016-02-21 |
|
[024fc0] Changed package name in package.json |
Schema middleware that makes it easy to flip a bit instead of removing docs.
npm install mongoose-soft-delete
Mount as standard middleware in your mongoose schemas.
const softDelete = require('mongoose-soft-delete');
const ExampleSchema = new mongoose.Schema({
field: String,
anotherField: String
});
ExampleSchema.plugin(softDelete);
mongoose.model('Example', ExampleSchema);
isDeleted path to schemas that is set to false by default. This path is indexed to improve query efficiencyfind and findOne queries that filter out documents where isDeleted is trueremove() method to set isDeleted to true instead of deleting the documentIn many applications, deleting all traces of a document is not desired. We often would rather hide them so that they can be recovered later or easily restored. This plugin makes it easier to implement this all at once and to remove the burden of having to remember to filter out deleted documents from every query.
Tests are coded in mocha and chai. Setup a local mongodb server and run npm install, then run npm test.