Home

Awesome

Soft Delete

Soft Delete is an easy way to add soft deletes to your Meteor app. Its key features are:

Usage

Add the package to your app

meteor add jam:soft-delete

Deleting permanently

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.

Explicitly soft deleting

If you prefer, you can explicity use softRemoveAsync, e.g.:

Collection.softRemoveAsync(/* your filter */)

Recovering a document

To recover a soft deleted document, use recoverAsync, e.g.:

Collection.recoverAsync(/* your filter */)

Configuring (optional)

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 ... //
});