-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.10.1
-
Component/s: API
-
None
-
Environment:Server: MongoDB 2.2.3 x64 version running on CentOS 6.3
Client: Sun JDK 1.6.0_31 x64 versuion, running on CentOS 6.3
I have a sharded MongoDB cluster which has 2 shards. Each shard has 1 primary node, 1 secondary node and 1 arbiter. The mongos runs on one of the cluster machines.
I use the following codes to connec to mongos:
Mongo mongo = new Mongo(args[0]);
DB emData = mongo.getDB(args[1]);
DBCollection publicationMonth = emData.getCollection(args[2]);
publicationMonth.setReadPreference(ReadPreference.secondary());
However, when I execute an aggregation on the "publicationMonth" collection, only the primary nodes are busy to execute the query while the secondary nodes sitting there idle.
If I modify above codes a little bit to:
Mongo mongo = new Mongo(args[0]);
mongo.setReadReference(ReadPreference.secondary());
DB emData = mongo.getDB(args[1]);
DBCollection publicationMonth = emData.getCollection(args[2]);
secondary nodes will execute the aggregation query instead of primary nodes.
- duplicates
-
JAVA-705 Query commands like aggregate and mapReduce don't pick up the read preference set on the collection
- Closed