Search in sources :

Example 21 with FindOptions

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

the class TestMapperOptions method customDiscriminators.

@Test
public void customDiscriminators() {
    getDs().getMapper().map(EntityDiscriminator.class, EntityDiscriminator2.class);
    EntityDiscriminator entityDiscriminator = new EntityDiscriminator();
    entityDiscriminator.name = "entityDiscriminator";
    EntityDiscriminator2 entityDiscriminator2 = new EntityDiscriminator2();
    entityDiscriminator2.name = "entityDiscriminator2";
    getDs().save(List.of(entityDiscriminator, entityDiscriminator2));
    Query<EntityDiscriminator2> query = getDs().find(EntityDiscriminator2.class).filter(ne("name", "hi"));
    List<EntityDiscriminator2> list = query.iterator(new FindOptions().logQuery()).toList();
    assertEquals(list.size(), 1, query.getLoggedQuery());
}
Also used : FindOptions(dev.morphia.query.FindOptions) Test(org.testng.annotations.Test)

Example 22 with FindOptions

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

the class TestMapperOptions method shouldFindField.

private void shouldFindField(Datastore datastore, HasMap hl, Map<String, String> expected) {
    final Document document;
    datastore.save(hl);
    document = getDocumentCollection(HasMap.class).find().first();
    assertTrue(document.containsKey("properties"), "Should find the field");
    assertEquals(datastore.find(HasMap.class).iterator(new FindOptions().limit(1)).tryNext().properties, expected);
    cleanup();
}
Also used : FindOptions(dev.morphia.query.FindOptions) Document(org.bson.Document)

Example 23 with FindOptions

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

the class TestGeoQueries method testWithinOutsideBox.

@Test
public void testWithinOutsideBox() {
    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(.4, .5)))).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 24 with FindOptions

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

the class TestGeoQueries method testGeoWithinPolygon.

@Test
public void testGeoWithinPolygon() {
    final Place place1 = new Place("place1", new double[] { 0, 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)).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 25 with FindOptions

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

the class TestGeoQueries method testWithinBox.

@Test
public void testWithinBox() {
    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)

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