Search in sources :

Example 1 with StringDates

use of dev.morphia.test.aggregation.experimental.model.StringDates in project morphia by mongodb.

the class TestDateExpression method testDateToString.

@Test
public void testDateToString() {
    LocalDate joined = LocalDate.parse("2016-05-01 UTC", DateTimeFormatter.ofPattern("yyyy-MM-dd z"));
    getDs().getCollection(User.class).drop();
    getDs().save(new User("John Doe", joined));
    Aggregation<User> pipeline = getDs().aggregate(User.class).project(project().include("string", dateToString().format("%Y-%m-%d").date(field("joined"))));
    MorphiaCursor<StringDates> it = pipeline.execute(StringDates.class);
    while (it.hasNext()) {
        assertEquals(it.next().getString(), "2016-05-01");
    }
}
Also used : User(dev.morphia.test.models.User) StringDates(dev.morphia.test.aggregation.experimental.model.StringDates) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

StringDates (dev.morphia.test.aggregation.experimental.model.StringDates)1 User (dev.morphia.test.models.User)1 LocalDate (java.time.LocalDate)1 Test (org.testng.annotations.Test)1