Search in sources :

Example 66 with FindOptions

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

the class TestGeoQueries method testGeoWithinBox.

@Test
public void testGeoWithinBox() {
    final Place place1 = new Place("place1", new double[] { 1, 1 });
    getDs().save(place1);
    final Place found = getDs().find(Place.class).filter(box("loc", new Point(new Position(0, 0)), new Point(new Position(2, 2)))).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 67 with FindOptions

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

the class TestGeoQueries method testGeoWithinRadius.

@Test
public void testGeoWithinRadius() {
    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, 1)), 1.1)).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 68 with FindOptions

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

the class TestMapperOptions method shouldNotFindField.

private void shouldNotFindField(Datastore datastore, HasList hl) {
    datastore.save(hl);
    Document document = getDocumentCollection(HasList.class).find().first();
    assertFalse(document.containsKey("names"), "field should not exist, value = " + document.get("names"));
    HasList hasList = datastore.find(HasList.class).iterator(new FindOptions().limit(1)).tryNext();
    assertNull(hasList.names);
    cleanup();
}
Also used : FindOptions(dev.morphia.query.FindOptions) Document(org.bson.Document)

Example 69 with FindOptions

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

the class TestGeoQueries method testNearNoIndex.

@Test(expectedExceptions = MongoQueryException.class)
public void testNearNoIndex() {
    getDs().getCollection(Place.class).drop();
    final Place place1 = new Place("place1", new double[] { 1, 1 });
    getDs().save(place1);
    Place found = getDs().find(Place.class).filter(near("loc", new Point(new Position(0, 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 70 with FindOptions

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

the class TestGeoQueries method testGeoWithinRadiusSphere.

@Test
public void testGeoWithinRadiusSphere() {
    final Place place1 = new Place("place1", new double[] { 1, 1 });
    getDs().save(place1);
    final Place found = getDs().find(Place.class).filter(centerSphere("loc", new Point(new Position(0, 1)), 1)).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)

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