-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.js
More file actions
33 lines (26 loc) · 831 Bytes
/
Copy pathdelete.js
File metadata and controls
33 lines (26 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
Connects to mongo and delete data
*/
var MongoClient = require('mongodb').MongoClient;
var waterfall = require('async').waterfall;
module.exports = function(ctx, cb) {
var MONGO_URL = ctx.data.MONGO_URL;
if (!MONGO_URL) return cb(new Error('MONGO_URL secret is missing'))
waterfall([
function connect_to_db(done) {
MongoClient.connect(MONGO_URL, function(err, db) {
if(err) return done(err);
done(null, db);
});
},
function do_delete(db, done) {
delete ctx.data.MONGO_URL;
db
.collection('users')
.deleteMany(ctx.data, function (err, results) {
if(err) return done(err);
done(null, 'succesful');
});
}
], cb);
};