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

distinct and count not go to secondary even we have specified the ReadPreference

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.9.0
    • Affects Version/s: 2.7.2
    • Component/s: Connection Management
    • Labels:
      None

      count/distict implementation of DBCollection do not take ReadPreference, so eventually it goes to Primary instead of Secondary even we have specified secondary preference.

      Here's the code caused this problem:
      public long getCount(DBObject query, DBObject fields, long limit, long skip )
      throws MongoException {

      BasicDBObject cmd = new BasicDBObject();
      cmd.put("count", getName());
      cmd.put("query", query);
      if (fields != null)

      { cmd.put("fields", fields); }

      if ( limit > 0 )
      cmd.put( "limit" , limit );
      if ( skip > 0 )
      cmd.put( "skip" , skip );

      CommandResult res = _db.command(cmd,getOptions());

      Here's when calling "_db.command(cmd,getOptions())" but not passing read preference, it works when I changed it to:
      CommandResult res = _db.command(cmd,getOptions(),this.getReadPreference());

      same issue for "distinct"

            Assignee:
            steve.briskin Steve Briskin (Inactive)
            Reporter:
            xiaofeng Xiaofeng Wu
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: