private void _check() {
[...]
if (_collection.getDB().getMongo().isMongosConnection()) {
builder.addReadPreference(_readPref);
}
Hey Jeff,
thanks for your quick reply! Here is my code snippet:
private DBCursor cursor( DB db, String id ) {
DBCollection col = db.getCollection( id );
BasicDBObject query = new BasicDBObject();
query.put( "uuid", new BasicDBObject( "$in", uuids ) );
return col.find( query ).setReadPreference( ReadPreference.secondary() );
}
I'm executing this against a single MongoDB instance that I bring up in my unit tests, no secondary. With a read preference of secondary, I expect this unit test to fail (according to http://docs.mongodb.org/manual/reference/read-preference/#secondary), but it works fine.
Christian
On Tuesday 14 October 2014 09:25:34 Jeff Yemin wrote:
> That code is misleading. The effect of adding the read preference to the
> QueryOpBuilder is to add a $readPreference field to the query
> specification, which is only necessary when sending the query to a mongos.
> When the driver is connected to a replica set, that's not necessary since
> the driver is responsible for routing.
>
> How are you setting the read preference? Can you provide some evidence to
> show that it's not working?
>
> For reference, here's a test
> <https://github.com/mongodb/mongo-java-driver/blob/2.12.x/src/test/com/mongo
> db/SecondaryReadTest.java#L75-104> demonstrating the expected behavior.