Search in sources :

Example 1 with AggregationOptions

use of com.mongodb.AggregationOptions in project morphia by mongodb.

the class AggregationTest method testOut.

@Test
public void testOut() {
    checkMinServerVersion(2.6);
    getDs().save(asList(new Book("The Banquet", "Dante", 2), new Book("Divine Comedy", "Dante", 1), new Book("Eclogues", "Dante", 2), new Book("The Odyssey", "Homer", 10), new Book("Iliad", "Homer", 10)));
    AggregationOptions options = builder().outputMode(AggregationOptions.OutputMode.CURSOR).build();
    Iterator<Author> aggregate = getDs().createAggregation(Book.class).group("author", grouping("books", push("title"))).out(Author.class, options);
    Assert.assertEquals(2, getDs().getCollection(Author.class).count());
    Author author = aggregate.next();
    Assert.assertEquals("Homer", author.name);
    Assert.assertEquals(asList("The Odyssey", "Iliad"), author.books);
    getDs().createAggregation(Book.class).group("author", grouping("books", push("title"))).out("different", Author.class);
    Assert.assertEquals(2, getDb().getCollection("different").count());
}
Also used : AggregationOptions(com.mongodb.AggregationOptions) Test(org.junit.Test)

Aggregations

AggregationOptions (com.mongodb.AggregationOptions)1 Test (org.junit.Test)1