FarscapePROJ
FarscapePROJ

Reputation: 285

Node.js "auth fail" when connecting to MongoDB Replicaset with only 2 out of the 3 servers up

I am having a strange issue when working with a Replica set of 3 instances with Authentication turned on, from Node.js

My problem is that when all 3 servers are listed in the seed list, within my application as soon as I connect to MongoDB it throws an "auth failed" error.

If I take out the server that is down from the seed list, everything works fine.

I am trying to figure out what I am missing and if there is another way to connect to a Replicaset from Node.js using the MongoClient.

var seedlist = "SERVER1:27017,SERVER2:27017,SERVER3:27017";
var connectionString = "mongodb://" + dbuser + ":" + dbpassword + "@" + seedlist + "/" + databaseName;

For this example lets say SERVER3 is down. Why would having it in the list cause an issue. Is the MongoDB Client from Node trying to authenticate to every member of the replica set?

Upvotes: 0

Views: 548

Answers (1)

FarscapePROJ
FarscapePROJ

Reputation: 285

Not sure i like how the Mongo client for Node throws the exception if only one of the members in the Seed list has an issue but here is what i found as the reason for my issue.

It turns out that through improper communication with Engineering, the Mongod instance on Server3 was indeed up. However, authentication had not been turned on for this instance.

From what i can gather, the Mongo Client for Node.js will attempt to authenticate to the members in the seed list and get information regarding the Replicaset. In this case because Server 3 did not have authentication turned on, it failed throwing an "auth fail" error.

My research was actually good, because i discovered that the seed list does NOT have to contain every member of the replica set. The client will use any of the members in the seed list to automatically determine ALL the members of the replica set.

Upvotes: 1

Related Questions