use of dev.morphia.Datastore in project morphia by mongodb.
the class TestMaxMin method testMaxCompoundIndex.
@Test
public void testMaxCompoundIndex() {
final IndexedEntity a1 = new IndexedEntity("a");
final IndexedEntity a2 = new IndexedEntity("a");
final IndexedEntity b1 = new IndexedEntity("b");
final IndexedEntity b2 = new IndexedEntity("b");
final IndexedEntity c1 = new IndexedEntity("c");
final IndexedEntity c2 = new IndexedEntity("c");
Datastore ds = getDs();
ds.save(a1);
ds.save(a2);
ds.save(b1);
ds.save(b2);
ds.save(c1);
ds.save(c2);
List<IndexedEntity> l = ds.find(IndexedEntity.class).iterator(new FindOptions().sort(ascending("testField"), ascending("id")).hint(new Document("testField", 1).append("_id", 1)).max(new Document("testField", "b").append("_id", b2.id))).toList();
Assert.assertEquals(l.size(), 3, "size");
Assert.assertEquals(l.get(2).id, b1.id, "item");
l = ds.find(IndexedEntity.class).iterator(new FindOptions().sort(ascending("testField"), ascending("id")).hint(new Document("testField", 1).append("_id", 1)).max(new Document("testField", "b").append("_id", b2.id))).toList();
Assert.assertEquals(l.size(), 3, "size");
Assert.assertEquals(l.get(2).id, b1.id, "item");
}
Aggregations