- 
    Type:Bug 
- 
    Resolution: Duplicate
- 
    Priority:Major - P3 
- 
    None
- 
    Affects Version/s: 3.0.3
- 
    Component/s: Async
- 
    None
- 
    Environment:Ubuntu 14.04, Java 8, Vertx
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
When i use the async driver and connect to a replica set (3 nodes), i get most of the time (66%+) and error:
com.mongodb.MongoNotPrimaryException: The server is not the primary and did not execute the operation
final MongoClientSettings clientSettings = MongoClientSettings.builder()
        .codecRegistry(CodecRegistries.fromRegistries(
                CodecRegistries.fromProviders(asList(new ValueCodecProvider(), new DocumentCodecProvider(), new BsonValueCodecProvider())),
                new VertxCodecRegistry()
        ))
        .clusterSettings(ClusterSettings.builder()
                .hosts(Lists.newArrayList(new ServerAddress(host, port)))
                .build())
        .readPreference(ReadPreference.nearest())                
        .build();
mongoClient = MongoClients.create(clientSettings);
FindIterable<JsonObject> find = mongoDatabase.getCollection(collectionName)
        .find(BsonDocument.parse(matcher.encode()), JsonObject.class);
if (projection != null && !projection.isEmpty()) {
    find = find.projection(BsonDocument.parse(projection.encode()));
}
if (page != null && !page.isEmpty()) {
    find.limit(page.getInteger("limit", 10));
    find.skip(page.getInteger("offset", 0));
}
find.into(new ArrayList<>(), (List<JsonObject> elements, Throwable error) -> {
    if (error != null) {
        LOG.warning("Could not execute query: " + matcher);
        message.fail(500, error.getMessage());
    } else {
        message.reply(new JsonArray(elements));
    }
});
If i use the sync driver or change the read preferences to primary everthing works fine. I suppose it is a bug?
- duplicates
- 
                    JAVA-1954 count/find query gives: MongoNotPrimaryException: The server is not the primary and did not execute the operation -         
- Closed
 
-