简体   繁体   中英

MongoDB : How to find if slaveOk=true is set or not

We are using Mongo DB in our Application . We have one primary and one secondary for this purpose .

How can i make sure that my Application is reading data from Primary Or Secondary ??

My question is how can i know if slaveOk=true is set or not ??

Thanks in advance .

Edited Part

Not sure of the Driver what i am uisng I am connecting Mongo DB through Java as shown

ServerAddress addr = new ServerAddress(new InetSocketAddress(host, port));
servAddrList.add(addr);
}
MongoOptions options = new MongoOptions();
options.autoConnectRetry = true;
options.connectionsPerHost = Config.intParam(
"mongo.connectionsPerHost", 1200);      
mongo = new Mongo("10.11.13.111", 27017);

And i am using mongo 2.4.jar

Please let m know how can i find what driver i am using ??

What are you looking for in my opinion is readPreference : http://docs.mongodb.org/manual/applications/replication/#replica-set-read-preference

In the api ( http://api.mongodb.org/java/2.10.1/com/mongodb/ReadPreference.html ) documentation there is an isSlaveOk() method : http://api.mongodb.org/java/2.10.1/com/mongodb/ReadPreference.html#isSlaveOk()

See this question: How to perform read operations from primary only

There is the answer for setting read preference

mongo.setReadPreference(ReadPreference.primary());

and your answer is to get read preference:

mongo.getReadPreference().isSlaveOk();

Unfortunately these features do not exist in versions after 2.4.

looks like earlier java driver just have mongo.slaveOk() method, call it and it is slaveOk. no way to examine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM