Properly close mongoose's connection once you're done
You can close the connection with
mongoose.connection.close()
The other answer didn't work for me. I had to use mongoose.disconnect();
as stated in this answer.
You can set the connection to a variable then disconnect it when you are done:
var db = mongoose.connect('mongodb://localhost:27017/somedb');
// Do some stuff
db.disconnect();