Created
October 17, 2017 03:58
-
-
Save sharkyak/e4a61dc032dd74dfef9bcb3d7434e9dc to your computer and use it in GitHub Desktop.
mongodb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MongoClient = require('mongodb').MongoClient; | |
function dbConnect(callback) { | |
MongoClient.connect(dbUrl, function(err, db) { | |
if (err) return console.log(err); | |
callback(db); | |
}); | |
} | |
function updateSubscriptions() { | |
dbConnect(function(db) { | |
var docs = db.collection('accounts').find( {} ); | |
docs.forEach(updateUserSubscription, function() {db.close()}); | |
}); | |
} | |
function cleanAccountsCollection() { | |
dbConnect(function(db) { | |
db.collection('accounts').remove({}, function(err) { | |
if (err) console.log(err); | |
db.close(); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment