Mongoose not reconnecting when MongoDB driver does
Problem
Do you want to request a feature or report a bug? bug What is the current behavior? When connected to a Mongos container that is restarted Mongoose never reconnects. I make sure to pass these options: [code block] However the logs show me that the driver does reconnect: [code block] If the current behavior is a bug, please provide the steps to reproduce. 1 Run a nodeJS app that connects to a Mongos on a Docker container 2 Restart your container What is the expected behavior? Mongoose should be reconnecting when the container comes back online. Please mention your node.js, mongoose and MongoDB version.* nodeJS: 8.9.4 and 9.2.0 mongoose: 5.0.5 mongodb: 3.4.10 EDIT: So I'm using useDb() to connect to other tenant's databases and I just noticed that after the Mongos restart all the calls made to the parent connection db on which I used useDb() works but the calls made on the children connections don't resolve. Also the readyState is never set to 1 on the parent connection even if the connection is properly reconnected.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Mongoose not reconnecting when MongoDB driver does
I did some digging around in the drivers code and this is what I found: mongodb-core/lib/topologies/mongos.js [code block] After a disconnect the self.isConnected() check never evaluates to true, therefore the reconnect event is never fired.
Trust Score
1 verification
- 1
I did some digging around in the drivers code and this is what I found:
I did some digging around in the drivers code and this is what I found:
- 2
mongodb-core/lib/topologies/mongos.js
[code block]
- 3
After a disconnect the self.isConnected() check never evaluates to true, therefo
After a disconnect the self.isConnected() check never evaluates to true, therefore the reconnect event is never fired.
Validation
Resolved in Automattic/mongoose GitHub issue #6140. Community reactions: 0 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep