2

I have a POC of a Mongo Replica (Mongo 3.0.14) set created locally using VirtualBox. I have a Primary, Secondary and Arbiter created and initiated in the replica set:

rs.status

Using Robomongo from my host machine (local OS, Win10), I am able to connect to the Primary and Secondary servers. I am unable to connect to the arbiter- though I think this may be expected? I wasn't able to find a clear answer to that question.

My connection string is as follows in a native 8.1 rev 160519 install:

<add name="analytics"       connectionString="mongodb://rootAdmin:rootAdmin@192.168.1.203/analytics?replicaSet=test-rs" />
<add name="tracking.live"   connectionString="mongodb://rootAdmin:rootAdmin@192.168.1.203/tracking_live?replicaSet=test-rs" />
<add name="tracking.history"    connectionString="mongodb://rootAdmin:rootAdmin@192.168.1.203/tracking_history?replicaSet=test-rs" />
<add name="tracking.contact"    connectionString="mongodb://rootAdmin:rootAdmin@192.168.1.203/tracking_contact?replicaSet=test-rs" />

I have tested with and without (current) the secondary server and arbiter included in the connection string, yet I receive the same error in the logs, always:

ERROR Unable to connect to a member of the replica set matching the read preference Primary

This error is followed by a number of other connection related issues, though this is the first error present.

The Mongo VM's are all running Ubuntu (v 16.04.2). From the Primary VM, I can authenticate to the Primary and Secondary instances, but not the arbiter. Prior to initiating the replica set, I created the same users on all Mongo instances and was able to login prior to the creation of the replica set.

I'm not 100% convinced that my issue is with the Arbiter, but it appears that I should be able to log in to it.

3

After reviewing the Mongo logs on the primary server, I found that I was receiving authentication errors for each connection attempt. Without specifying the authSource, Mongo uses the database defined in the connection string. Therefore a connection string like:

<add name="analytics" connectionString="mongodb://rootAdmin:rootAdmin@192.168.1.131/analytics?replicaSet=test-rs" />

uses the analytics database when authenticating the rootAdmin user. Since there are no users defined in this database, the authentication fails. To get around this, you need to add an additional parameter: authSource.

Following the MongoDocs verbatim ends up causing a configuration error:

...analytics?authSource=admin&replicaSet=test-rs

The solution is to encode the & character. This allows you to pass in as many parameters as you wish:

...analytics?authSource=admin&amp;replicaSet=test-rs

Finally, to ensure a connection to all members in the replica set, the multiple members need to be defined as follows:

<add name="analytics" connectionString="mongodb://rootAdmin:rootAdmin@192.168.1.131,192.168.1.203,192.168.1.194/analytics?authSource=admin&amp;replicaSet=test-rs" />

I was able to confirm that data is now being written to both the Primary and Secondary servers and the arbiter is participating in voting properly.

Also of note, the Arbiter MUST be able to authenticate with the given user. I redid my arbiter and made sure to create the users against the admin database. By default, users are created in the test database.

0

Can you try passing all your servers into connection string like below:

 <add name="tracking.live" connectionString="mongodb://rootAdmin:rootAdmin@192.168.1.SERVER1,rootAdmin:rootAdmin@192.168.1.SERVER2,rootAdmin:rootAdmin@192.168.1.SERVER3/analytics?replicaSet=rs_test" />

When I compared your connection string with mine I found that I was using all 3 servers in my connection string and you were only using one.

Also you can follow this link for @ symbol issue: How to format the connection string for a MongoDB replica set in Sitecore?

  • Thanks for the suggestion, but that did not help. I decided to look into the Mongo logs and saw all of my connection attempts. SCRAM-SHA-1 authentication failed for rootAdmin on tracking_history from client 192.168.1.29 ; UserNotFoudn Could not find user rootAdmin@tracking_history – jrap Apr 18 '17 at 19:30
  • It's odd to me that I can connect using RoboMongo. Almost like Sitecore doesn't authenticate properly. Whenever I've tried adding additional parameters to the connection it immediately fails with a config error. I've tried adding parameters such as: authMechanism and authSource and it's never happy. – jrap Apr 18 '17 at 19:32
  • do you have @ symbol in your password? or some other special character? – Mrunal Daftari Apr 18 '17 at 19:48
  • No, the password is simply rootAdmin. I will post my answer shortly, I've figured it out. – jrap Apr 18 '17 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.