4

In a hosted MEAN stack application the following happened with the MongoDB replica set as reported by the hosting company's tech support:

There was a three minute window where a new primary was briefly elected. It looks like some network issues caused the primary to lose connection to the secondaries. The window was only 3 minutes and the primary was then re-elected normally.

Once everything was back to normal my Node.js application, which uses the Mongoose framework, did not re-establish its connection to the primary causing a "Cannot write to a secondary" error to be logged.

Question: What setting(s) when using Mongoose and/or the MongoDB Driver that it uses could prevent the automatic reconnect after the primary switched back? (i.e. how do I prevent this from happening again?)

Using Mongoose v3.8.26

Guy
  • 65,082
  • 97
  • 254
  • 325
  • Could you post your connection string? Some sort of deployment diagram might be useful, too. Maybe we can see sth there. This shouldn't happen, as you correctly assume. The only thing I can think of is that there was network partitioning going on between the primary and both secondaries, forcing the secondaries to hold an election, as stated. The question remains why the driver could not find the new primary. Something very strange was happening there. – Markus W Mahlberg Apr 19 '15 at 19:49
  • @MarkusWMahlberg the connection string takes the form: mongodb://:@:/ – Guy Apr 20 '15 at 20:54
  • 2
    I wanted to see *your* connection string o.o But we may have found the problem here. Albeit the members of a replica set and elections **should** be announced to the driver, this seems not to be the case here. Please use `mongoose.connect('mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]' [, options]);` for connections to a replica set as per documentation, where host1 - hostN denote the replica set members. If at all possible, please test this setup. You could use a local firewall to emulate network partitioning. – Markus W Mahlberg Apr 21 '15 at 04:10

0 Answers0