From 4883e66a96c8082b05b427168bb5062fd29f1654 Mon Sep 17 00:00:00 2001 From: Kevin Kuehler Date: Mon, 4 May 2020 16:39:29 -0700 Subject: [PATCH] Minor fixups * assert we use non-deprecated moment.subtract(num, period) * close mongo client and not the connection --- bin/remove-feedback.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bin/remove-feedback.js b/bin/remove-feedback.js index 45fc5e53..d435e28d 100755 --- a/bin/remove-feedback.js +++ b/bin/remove-feedback.js @@ -15,8 +15,10 @@ const args = require('yargs') .argv const main = async (args) => { - MongoClient.connect(mongoURL, (err, connection) => { - const collection = connection.collection(FEEDBACK_COLLECTION); + MongoClient.connect(mongoURL, (err, client) => { + const db = client.db() + + const collection = db.collection(FEEDBACK_COLLECTION); if (args.id) { collection.deleteOne({ id : args.id }, (err, result) => { assert.equal(err, null) @@ -25,11 +27,12 @@ const main = async (args) => { } else { console.log(`Feedback with id ${args.id} removed`) } - connection.close() + client.close() }) } else if (args.interval) { let [num, period] = args.interval.split(' ') num = parseInt(num) + assert(typeof(period) === 'string') const targetYMD = moment().subtract(num, period).format('YYYY-MM-DD') console.log(`This will remove all feedback before ${targetYMD}. Run again with -f to accept`) if (targetYMD && args.f) { @@ -37,13 +40,13 @@ const main = async (args) => { collection.deleteMany({ ymd: { $lt: targetYMD }}, (err, result) => { assert.equal(err, null) console.log(`${result.result.n} feedback records removed`) - connection.close() + client.close() }) } else { - connection.close() + client.close() } } else { - connection.close() + client.close() } }) }