mongoose-deleted
a soft-delete implementation utilizing mongoose middleware
usage
var mongoose = ;var mongoose_deleted = ;var user = name: String ;;user = mongoose; var name = "John Q Public";var user1 = name : name ; user1;
documents
mongoose-deleted
utilizes mongoose middleware to transparently modify queries to select for documents that are not { deleted: true }
. Documents that are .delete()
-ed will not be returned. To explicitly return documents that are deleted:
schema;
Additionally, the deleted
boolean property is set by default to not be selected/returned on a document.
To have deleted
normally returned:
schema;
To have the deleted
property included, in addition to the normal properties:
schema;
Or, to retrieve the deleted
property only on a particular query, manually select for it:
schema;
toJSON
By default, mongoose-deleted
hides the deleted
property on doc.toJSON()
. This is configurable in the options:
schema;
This can be overriden in a toJSON()
call:
var json = doc;
history
mongoose-deleted
allows an optional integration with mongoose-history-log
by passing in the options:
;
This will automatically insert a { status: 'deleted' }
object with the current time.