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");
}
}
Aggregations