use of dev.morphia.UpdateOptions in project morphia by mongodb.
the class TestDatastore method testUpdateWithCollation.
@Test
public void testUpdateWithCollation() {
getDs().save(asList(new FacebookUser(1, "John Doe"), new FacebookUser(2, "john doe")));
final Update<FacebookUser> update = getDs().find(FacebookUser.class).filter(eq("username", "john doe")).update(inc("loginCount"));
UpdateResult results = update.execute();
assertEquals(results.getModifiedCount(), 1);
assertEquals(getDs().find(FacebookUser.class).filter(eq("id", 1)).iterator(new FindOptions().limit(1)).next().loginCount, 0);
assertEquals(getDs().find(FacebookUser.class).filter(eq("id", 2)).iterator(new FindOptions().limit(1)).next().loginCount, 1);
results = update.execute(new UpdateOptions().multi(true).collation(Collation.builder().locale("en").collationStrength(SECONDARY).build()));
assertEquals(results.getModifiedCount(), 2);
assertEquals(getDs().find(FacebookUser.class).filter(eq("id", 1)).iterator(new FindOptions().limit(1)).next().loginCount, 1);
assertEquals(getDs().find(FacebookUser.class).filter(eq("id", 2)).iterator(new FindOptions().limit(1)).next().loginCount, 2);
}
Aggregations