In my opinion, you are trying to create another connection without closing the current one. So, you might want to use:
createConnection() instead of connect()
.
In your case, it would look like this:
db = mongoose.createConnection('mongodb://localhost/mydb');