I have a one-time Node script that makes some changes to the MongoDB database on MongoLab. However, once it finishes, it never exits the event loop (I always need ctrl + C it), no matter how much I do db.close() and db.logout() .
Which is strange, if I run a local executable instance of mongod and connect to it, the script ends fine, but the remote connection just doesn't end.
Here is a short version of my script that still has a problem (with the url on the server on the command line). What's happening?
var mongodb = require("mongodb"); function onSuccess(cb){ return function(err) { if (err) { console.error(err) } else { cb.apply(this,Array.prototype.slice.call(arguments,1)) } } } console.log("Connecting to "+process.argv[2]+' ...'); mongodb.MongoClient.connect(process.argv[2],onSuccess(function(db){ console.log("Connected."); db.logout(onSuccess(function(logoutResult){ db.close(onSuccess(function(closeResult){ console.log("All finished. Can has prompt return nao?") })); })); }));
source share