From 66fe339f4b7f2dfb91d5b0dfd4fcd84fbcfa45fc Mon Sep 17 00:00:00 2001 From: Rafael Diaz-Tushman Date: Mon, 20 Jun 2016 12:20:34 -0400 Subject: [PATCH] Added indexes to deleted, deletedAt, deletedBy --- index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index f4df28b..864bc2c 100644 --- a/index.js +++ b/index.js @@ -47,16 +47,17 @@ module.exports = function (schema, options) { schema.add({ deleted: { type: Boolean, - default: false + default: false, + index: true } }); if (options && options.deletedAt === true) { - schema.add({ deletedAt: { type: Date} }); + schema.add({ deletedAt: { type: Date, index: true } }); } if (options && options.deletedBy === true) { - schema.add({ deletedBy: Schema.Types.ObjectId }); + schema.add({ deletedBy: Schema.Types.ObjectId, index: true }); } schema.pre('save', function (next) { @@ -90,7 +91,7 @@ module.exports = function (schema, options) { finalList.forEach(function(method) { if (method === 'count' || method === 'find' || method === 'findOne') { schema.statics[method] = function () { - return Model[method].apply(this, arguments).where('deleted').equals(false); + return Model[method].apply(this, arguments).where('deleted').ne(true); }; schema.statics[method + 'Deleted'] = function () { return Model[method].apply(this, arguments).where('deleted').ne(false);