use of dev.morphia.DeleteOptions in project morphia by mongodb.
the class TestVersioning method testVersionedUpsert.
@Test
public void testVersionedUpsert() {
final Datastore datastore = getDs();
datastore.find(Versioned.class).delete(new DeleteOptions().multi(true));
Versioned entity = new Versioned();
entity.setName("Value 1");
Query<Versioned> query = datastore.find(Versioned.class);
query.filter(eq("name", "Value 1"));
query.update(set("name", "Value 3")).execute(new UpdateOptions().upsert(true));
entity = datastore.find(Versioned.class).iterator(new FindOptions().limit(1)).tryNext();
assertEquals(entity.getName(), "Value 3");
assertEquals(entity.getVersion().longValue(), 1);
}
Aggregations