Skip to content

Instantly share code, notes, and snippets.

@sharkyak
Created October 17, 2017 03:58
Show Gist options
  • Save sharkyak/e4a61dc032dd74dfef9bcb3d7434e9dc to your computer and use it in GitHub Desktop.
Save sharkyak/e4a61dc032dd74dfef9bcb3d7434e9dc to your computer and use it in GitHub Desktop.
mongodb
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