Open jeffj opened 12 years ago
Huh, I hadn't even thought about it. Good point. I don't think you can do that now, ...
You can quickly add a handler in mongous.js, inside of mongous
:
mongous.prototype.close = function(){ con.c.end() }
con.c
in mongous.js is the require('net')
object that does all the talking to MongoD.
This should work, I haven't tested it though, if it doesn't you might have to add a super wrapper for it (which isn't hard once you peek at the code, it is pretty short). But I will keep it in mind next time I update Mongous.
It should be pretty easy, though, to add. If you do, let me know and I'll merge your fork.
Then just set your mongous variable to null.
I added mongous.prototype.close = function(){ con.c.end() } at line 233 but I get the node error:
"node.js:201 throw e; // process.nextTick error, or 'error' event on first tick ^ RangeError: Maximum call stack size exceeded"
Hmm, I just tried it, and you are right, I get an error too. If I use con.c.destroy() I also get an error. I know those are the methods that Node's net API says to use, and it isn't giving me really any debugging information (and I suck at debugging). If you could keep working on this, that would be nice. Elsewise I'll get around to it later (later = when I personally need it, which I don't foresee being any time soon).
It definitely should be implemented, though. Why do you need it, out of curiosity?
I want to use node for an program that is not a webserver. The application will access and upload information them the process will terminate. The connection to mongo is a prerequisite for this I think. My work around is to use a chron module in node so ending the .js script is no longer required.
How can I terminate the DB connection and all the instances of mongous functions?