Search in sources :

Example 6 with DeleteOptions

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);
}
Also used : FindOptions(dev.morphia.query.FindOptions) DeleteOptions(dev.morphia.DeleteOptions) Datastore(dev.morphia.Datastore) Morphia.createDatastore(dev.morphia.Morphia.createDatastore) Versioned(dev.morphia.test.models.versioned.Versioned) UpdateOptions(dev.morphia.UpdateOptions) Test(org.testng.annotations.Test)

Aggregations

DeleteOptions (dev.morphia.DeleteOptions)6 Test (org.testng.annotations.Test)6 FindOptions (dev.morphia.query.FindOptions)3 UpdateOptions (dev.morphia.UpdateOptions)2 Versioned (dev.morphia.test.models.versioned.Versioned)2 DeleteResult (com.mongodb.client.result.DeleteResult)1 Datastore (dev.morphia.Datastore)1 Morphia.createDatastore (dev.morphia.Morphia.createDatastore)1 FindAndDeleteOptions (dev.morphia.query.FindAndDeleteOptions)1 City (dev.morphia.test.models.City)1 ContainsPic (dev.morphia.test.query.TestQuery.ContainsPic)1 Pic (dev.morphia.test.query.TestQuery.Pic)1 ArrayList (java.util.ArrayList)1 Document (org.bson.Document)1 ObjectId (org.bson.types.ObjectId)1