Search in sources :

Example 61 with FindOptions

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

the class InstanceCreationTest method basicReference.

@Test
public void basicReference() {
    final Author author = new Author("Jane Austen");
    getDs().save(author);
    final Author loaded = getDs().find(Author.class).iterator(new FindOptions().limit(1)).tryNext();
    assertEquals(author, loaded);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Test(org.testng.annotations.Test)

Example 62 with FindOptions

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

the class TestGeoQueries method testWithinRadius2.

@Test
public void testWithinRadius2() {
    final Place place1 = new Place("place1", new double[] { 1, 1 });
    getDs().save(place1);
    final Place found = getDs().find(Place.class).filter(center("loc", new Point(new Position(0.5, 0.5)), 0.77)).iterator(new FindOptions().limit(1)).next();
    Assert.assertNotNull(found);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Position(com.mongodb.client.model.geojson.Position) Point(com.mongodb.client.model.geojson.Point) Test(org.testng.annotations.Test)

Example 63 with FindOptions

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

the class TestGeoQueries method testGeoWithinPolygon2.

@Test
public void testGeoWithinPolygon2() {
    final Place place1 = new Place("place1", new double[] { 10, 1 });
    getDs().save(place1);
    final Place found = getDs().find(Place.class).filter(polygon("loc", new Point(new Position(0, 0)), new Point(new Position(0, 5)), new Point(new Position(2, 3)), new Point(new Position(2, 0)))).iterator(new FindOptions().limit(1)).tryNext();
    Assert.assertNull(found);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Position(com.mongodb.client.model.geojson.Position) Point(com.mongodb.client.model.geojson.Point) Test(org.testng.annotations.Test)

Example 64 with FindOptions

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

the class TestGeoQueries method testNear.

@Test
public void testNear() {
    final Place place1 = new Place("place1", new double[] { 1, 1 });
    getDs().save(place1);
    final Place found = getDs().find(Place.class).filter(near("loc", new Point(new Position(0, 0)))).iterator(new FindOptions().limit(1)).next();
    Assert.assertNotNull(found);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Position(com.mongodb.client.model.geojson.Position) Point(com.mongodb.client.model.geojson.Point) Test(org.testng.annotations.Test)

Example 65 with FindOptions

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

the class TestGeoQueries method testNearMaxDistance.

@Test
public void testNearMaxDistance() {
    final Place place1 = new Place("place1", new double[] { 1, 1 });
    getDs().save(place1);
    FindOptions options = new FindOptions().logQuery().limit(1);
    Query<Place> query = getDs().find(Place.class).filter(near("loc", new Point(new Position(1, 1))).maxDistance(2.0));
    Assert.assertNotNull(query.iterator(options).tryNext(), query.getLoggedQuery());
    query = getDs().find(Place.class).filter(near("loc", new Point(new Position(0, 0))).maxDistance(1.0));
    Assert.assertNull(query.first(options), query.getLoggedQuery());
}
Also used : FindOptions(dev.morphia.query.FindOptions) Position(com.mongodb.client.model.geojson.Position) Point(com.mongodb.client.model.geojson.Point) Test(org.testng.annotations.Test)

Aggregations

FindOptions (dev.morphia.query.FindOptions)118 Test (org.testng.annotations.Test)114 Point (com.mongodb.client.model.geojson.Point)16 Position (com.mongodb.client.model.geojson.Position)16 Document (org.bson.Document)16 Rectangle (dev.morphia.test.models.Rectangle)13 Datastore (dev.morphia.Datastore)12 UpdateResult (com.mongodb.client.result.UpdateResult)8 UpdateOptions (dev.morphia.UpdateOptions)8 ObjectId (org.bson.types.ObjectId)7 ValidationException (dev.morphia.query.ValidationException)6 User (dev.morphia.test.models.User)5 ContainsPic (dev.morphia.test.query.TestQuery.ContainsPic)5 Pic (dev.morphia.test.query.TestQuery.Pic)5 LocalDate (java.time.LocalDate)5 Date (java.util.Date)5 DeleteOptions (dev.morphia.DeleteOptions)4 Query (dev.morphia.query.Query)4 DocumentValidation (dev.morphia.test.models.DocumentValidation)4 ContainsPic (dev.morphia.test.query.TestLegacyQuery.ContainsPic)4