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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 2.7.2
    • 2.9.0
    • Connection Management
    • None

    Description

      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"

      Attachments

        Issue Links

          Activity

            People

              steve.briskin Steve Briskin
              xiaofeng Xiaofeng Wu
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: