@akeating-redhat/mongodb-lock
Version:
Locks which uses MongoDB's atomic operations.
24 lines (20 loc) • 570 B
JavaScript
var mongodb = require('mongodb')
var conStr = 'mongodb://localhost:27017/mongodb-lock'
module.exports = function(callback) {
mongodb.MongoClient.connect(conStr, function(err, db) {
if (err) throw err
var done = 0
// let's empty out some collections to make sure there are no messages
var collections = [
'default', 'locks', 'lock2',
]
collections.forEach(function(col) {
db.collection(col).remove(function() {
done += 1
if ( done === collections.length ) {
callback(db)
}
})
})
})
}