Search in sources :

Example 1 with CountOptions

use of dev.morphia.query.CountOptions in project morphia by mongodb.

the class TestLegacyQuery method testCollations.

@Test
public void testCollations() {
    getMapper().map(ContainsRenamedFields.class);
    getDs().save(asList(new ContainsRenamedFields("first", "last"), new ContainsRenamedFields("First", "Last")));
    Query query = getDs().find(ContainsRenamedFields.class).field("last_name").equal("last");
    assertEquals(query.execute().toList().size(), 1);
    assertEquals(query.execute(new FindOptions().collation(builder().locale("en").collationStrength(CollationStrength.SECONDARY).build())).toList().size(), 2);
    assertEquals(query.count(), 1);
    assertEquals(query.count(new CountOptions().collation(builder().locale("en").collationStrength(CollationStrength.SECONDARY).build())), 2);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Query(dev.morphia.query.Query) CountOptions(dev.morphia.query.CountOptions) Test(org.testng.annotations.Test)

Example 2 with CountOptions

use of dev.morphia.query.CountOptions in project morphia by mongodb.

the class TestQuery method testCollations.

@Test
public void testCollations() {
    getMapper().map(ContainsRenamedFields.class);
    getDs().save(asList(new ContainsRenamedFields("first", "last"), new ContainsRenamedFields("First", "Last")));
    Query query = getDs().find(ContainsRenamedFields.class).filter(eq("last_name", "last"));
    assertEquals(query.iterator().toList().size(), 1);
    assertEquals(query.iterator(new FindOptions().collation(builder().locale("en").collationStrength(CollationStrength.SECONDARY).build())).toList().size(), 2);
    assertEquals(query.count(), 1);
    assertEquals(query.count(new CountOptions().collation(builder().locale("en").collationStrength(CollationStrength.SECONDARY).build())), 2);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Query(dev.morphia.query.Query) CountOptions(dev.morphia.query.CountOptions) Test(org.testng.annotations.Test)

Aggregations

CountOptions (dev.morphia.query.CountOptions)2 FindOptions (dev.morphia.query.FindOptions)2 Query (dev.morphia.query.Query)2 Test (org.testng.annotations.Test)2