From 67acfa2d4b442bdf3f87593d6c39009c39b061fd Mon Sep 17 00:00:00 2001 From: saintedlama Date: Mon, 30 Nov 2015 17:06:22 +0100 Subject: [PATCH] Simplify remove --- lib/collection.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/collection.js b/lib/collection.js index 0855e6b..bec45e5 100644 --- a/lib/collection.js +++ b/lib/collection.js @@ -134,18 +134,12 @@ Collection.prototype.remove = function (query, options, cb) { this._getCollection(function (err, collection) { if (err) return cb(err) - // TODO: Duplicate code - see xtend below - if (options.justOne) { - collection.deleteOne(query, xtend(writeOpts, options), function (err, result) { - if (err) return cb(err) - cb(null, result.result) - }) - } else { - collection.deleteMany(query, xtend(writeOpts, options), function (err, result) { - if (err) return cb(err) - cb(null, result.result) - }) - } + var deleteOperation = options.justOne?'deleteOne':'deleteMany'; + + collection[deleteOperation](query, xtend(writeOpts, options), function (err, result) { + if (err) return cb(err) + cb(null, result.result) + }) }) }