Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-766

DBCollection.setReadReference() has no effect

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            drowndog Yibing Shi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: