I\'m totally new to mongoDB and not experienced with Node.js so please excuse if the code below is far from perfect.
The goal is to remove a document from a collecti
Welcome to asynchronous style:
db.close() should be in the callback, after removing is done.Example:
MongoClient.connect('mongodb://localhost/mochatests', function(err, db) {
db.collection('contacts', {}, function(err, contacts) {
contacts.remove({_id: ObjectID("52b2f757b8116e1df2eb46ac")}, function(err, result) {
if (err) {
console.log(err);
}
console.log(result);
db.close();
});
});
});