Soft Delete is an easy way to add soft deletes to your Meteor app. Its key features are:
- Zero config needed (though you can customize)
- Isomorphic so that it works with Optimistic UI
- Automatically overrides
removeAsync
to make it a soft delete - Automatically adds the soft delete flag on
insertAsync
and to the filter for your queries, e.g..find
, so you don't need to make any changes to them - Recover soft deleted docs with
recoverAsync
collection method - Explicitly soft delete with
softRemoveAsync
collection method (optional) - Optionally add a
deletedAt
timestamp - Optionally exclude specific collections
- Compatible with Meteor
2.8.1+
and3.0+
meteor add jam:soft-delete
By default, this package overrides the removeAsync
collection method so that it soft deletes the document(s) with a boolean flag rather that removing them from the database. To delete permanently, pass in the option soft: false
, e.g.:
Collection.removeAsync(/* your filter */, { soft: false })
If you prefer, you can prevent overriding the removeAsync
by setting overrideRemove: false
. See Configuring for more details.
If you prefer, you can explicity use softRemoveAsync
, e.g.:
Collection.softRemoveAsync(/* your filter */)
To recover a soft deleted document, use recoverAsync
, e.g.:
Collection.recoverAsync(/* your filter */)
If you like the defaults, then you won't need to configure anything. But there is some flexibility in how you use this package.
Here are the global defaults:
const config = {
deleted: 'deleted', // the field name used for the boolean flag. you can update to your preference, e.g. 'isDeleted'
deletedAt: '', // add the name of the field you'd like to use for a deletedAt timestamp, e.g. 'deletedAt', if you want to include it on your docs
autoFilter: true, // automatically adds the { [deleted]: false } filter to your queries
overrideRemove: true, // overrides the Collection.removeAsync method to make it a soft delete instead
exclude: ['roles', 'role-assignment'] // exclude specific collections from using soft delete. defaults to excluding the collections created the meteor roles package
};
To change the global defaults, use:
// put this in a file that's imported on both the client and server
import { SoftDelete } from 'meteor/jam:soft-delete';
SoftDelete.configure({
// ... change the defaults here ... //
});