Search in sources :

Example 1 with DBCollectionCountOptions

use of com.mongodb.client.model.DBCollectionCountOptions in project mongo-java-driver by mongodb.

the class DBCursor method getDbCollectionCountOptions.

private DBCollectionCountOptions getDbCollectionCountOptions() {
    DBCollectionCountOptions countOptions = new DBCollectionCountOptions().readPreference(getReadPreferenceForCursor()).readConcern(getReadConcern()).collation(getCollation()).maxTime(findOptions.getMaxTime(MILLISECONDS), MILLISECONDS);
    Object hint = findOptions.getModifiers().get("$hint");
    if (hint != null) {
        if (hint instanceof String) {
            countOptions.hintString((String) hint);
        } else {
            countOptions.hint((DBObject) hint);
        }
    }
    return countOptions;
}
Also used : DBCollectionCountOptions(com.mongodb.client.model.DBCollectionCountOptions) DBObjects.toDBObject(com.mongodb.DBObjects.toDBObject)

Example 2 with DBCollectionCountOptions

use of com.mongodb.client.model.DBCollectionCountOptions in project morphia by mongodb.

the class CountOptionsTest method passThrough.

@Test
public void passThrough() {
    Collation collation = Collation.builder().locale("en").caseLevel(true).build();
    DBCollectionCountOptions options = new CountOptions().collation(collation).hint("i'm a hint").limit(18).maxTime(15, TimeUnit.MINUTES).readPreference(ReadPreference.secondaryPreferred()).readConcern(ReadConcern.LOCAL).skip(12).getOptions();
    assertEquals(collation, options.getCollation());
    assertEquals("i'm a hint", options.getHintString());
    assertEquals(18, options.getLimit());
    assertEquals(15, options.getMaxTime(TimeUnit.MINUTES));
    assertEquals(ReadPreference.secondaryPreferred(), options.getReadPreference());
    assertEquals(ReadConcern.LOCAL, options.getReadConcern());
    assertEquals(12, options.getSkip());
}
Also used : DBCollectionCountOptions(com.mongodb.client.model.DBCollectionCountOptions) DBCollectionCountOptions(com.mongodb.client.model.DBCollectionCountOptions) Collation(com.mongodb.client.model.Collation) Test(org.junit.Test)

Aggregations

DBCollectionCountOptions (com.mongodb.client.model.DBCollectionCountOptions)2 DBObjects.toDBObject (com.mongodb.DBObjects.toDBObject)1 Collation (com.mongodb.client.model.Collation)1 Test (org.junit.Test)1