collection-softremovable

Ajoute dynamiquement à une collection des champs et fonctions pour placer des documents supprimés à la corbeille au lieu d'une suppression définitive.

Installation

meteor add zimme:collection-softremovable

Configuration d'une collection

Posts = new Mongo.Collection('posts');

//Attach behaviour with the default options
Posts.attachBehaviour('softRemovable');

//Attach behaviour with custom options
Posts.attachBehaviour('softRemovable', {
  removed: 'deleted',
  removedBy: false,
  restoredAt: 'undeletedAt',
  restoredBy: false
});

Remove/Restore

// Soft remove document by _id
Posts.softRemove({_id: 'BFpDzGuWG8extPwrE'});

// Restore document by _id
Posts.restore('BFpDzGuWG8extPwrE');

// Actually remove document from collection
Posts.remove({_id: 'BFpDzGuWG8extPwrE'});

Recherches

// Find all posts except soft removed posts
Posts.find({});

// Find only posts that have been soft removed
Posts.find({removed: true});

// Find all posts including removed
Posts.find({}, {removed: true});