-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.7.2
-
Component/s: Connection Management
-
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)
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"
- is related to
-
JAVA-497 ReadPrefs ignored for commands
- Closed