Ok I have two nodes setup with a replicaset on a linux server.
In the c# application using 1.8.1.20 driver I have
client = new MongoClient("mongodb://54.244.162.21,54.234.244.182/rs0?connect=replicaset;replicaSet=rs0;slaveOk=true;readPreference=primaryPreferred");
-When I connect with mongo to each node both master and slave the updates and find statements work properly.
-When I try to bring down any node either the primary or secondary I get: Unable to connect to a member of the replica set matching the read preference Primary
-When both nodes are up I get no error and everything works fine.
-I have tried to change the readPreference to every possible value because I want to see how the redundancy works.
Am I getting something wrong. I am assuming that you should be able to connect to either one and at least get reads working. The following code is what I have that the exception occurs on obviously when the connection is first established.
server = client.GetServer();
foreach (string db in server.GetDatabaseNames())
{
Debug.WriteLine(db);
}
The problem is that some database commands can only run on the primary. If you issue one while connecting to a replica set which has no primary then you get this error.
The command in this case is server.GetDatabaseNames() - it's possible that it was an oversight that it is not able to run this command on the secondary, but for the moment that is the case.
I'm going to check with the folks who maintain MongoDB drivers and see if this command should be allowed on a secondary or not.
For your example, I think you will find that if your program connected and then issued read queries, then it would work fine.
Ok I have two nodes setup with a replicaset on a linux server.
In the c# application using 1.8.1.20 driver I have
client = new MongoClient("mongodb://54.244.162.21,54.234.244.182/rs0?connect=replicaset;replicaSet=rs0;slaveOk=true;readPreference=primaryPreferred");
-When I connect with mongo to each node both master and slave the updates and find statements work properly.
-When I try to bring down any node either the primary or secondary I get: Unable to connect to a member of the replica set matching the read preference Primary
-When both nodes are up I get no error and everything works fine.
-I have tried to change the readPreference to every possible value because I want to see how the redundancy works.
Am I getting something wrong. I am assuming that you should be able to connect to either one and at least get reads working. The following code is what I have that the exception occurs on obviously when the connection is first established.
server = client.GetServer();
foreach (string db in server.GetDatabaseNames())
{
Debug.WriteLine(db);
}
The problem is that some database commands can only run on the primary. If you issue one while connecting to a replica set which has no primary then you get this error.
The command in this case is server.GetDatabaseNames() - it's possible that it was an oversight that it is not able to run this command on the secondary, but for the moment that is the case.
I'm going to check with the folks who maintain MongoDB drivers and see if this command should be allowed on a secondary or not.
For your example, I think you will find that if your program connected and then issued read queries, then it would work fine.
0 commentaires:
Enregistrer un commentaire