Package com.mongodb

Examples of com.mongodb.AggregationOutput


    @Test
    public void groupShortcutTest() {
        String testName = "groupShortcutTest";
        DBCollection collection = getCollection(testName);
        insertArticles(collection);
        AggregationOutput output = AggregateBuilder.aggregate(collection)
                .group("_id", "$author")
                .sort(DBO.of("_id", 1))
                .run();
        verifyAggregationOutputFromResources(testName, output);
    }
View Full Code Here


    @Test
    public void sortTest() {
        String testName = "sortTest";
        DBCollection collection = getCollection(testName);
        insertScoredTests(collection);
        AggregationOutput output = AggregateBuilder.aggregate(collection)
                .sort(DBO.of("score", -1))
                .run();
        verifyAggregationOutputFromResources(testName, output);
    }
View Full Code Here

    }

    @Test
    public void statesWithPopulationsOverTenMillionTest() {
        String testName = "statesWithPopulationsOverTenMillionTest";
        AggregationOutput output = AggregateBuilder.aggregate(collection)
                .group(GroupBuilder.start()
                        .put("_id").to("$state")
                        .put("totalPop").sum("$pop")
                )
                .match(QueryBuilder.start()
View Full Code Here

    }

    @Test
    public void averageCityPopulationByStateTest() {
        String testName = "averageCityPopulationByStateTest";
        AggregationOutput output = AggregateBuilder
                .aggregate(collection)
                .group(GroupBuilder.start()
                        .put("_id")
                        .to(new BasicDBObject()
                                .append("state", "$state")
View Full Code Here

    }

    @Test
    public void largestAndSmallestCitiesByStateTest() {
        String testName = "largestAndSmallestCitiesByStateTest";
        AggregationOutput output = AggregateBuilder
                .aggregate(collection)
                .group(GroupBuilder.start()
                        .put("_id")
                        .to(new BasicDBObject()
                                .append("state", "$state")
View Full Code Here

        DB database = client.getDB("m101");
        DBCollection collection = database.getCollection("funnynumbers");

        // Not necessary yet to understand this.  It's just to prove that you
        // are able to run a command on a mongod server
        AggregationOutput output =
                collection.aggregate(
                        new BasicDBObject("$group",
                                new BasicDBObject("_id", "$value")
                                        .append("count", new BasicDBObject("$sum", 1)))
                        ,
                        new BasicDBObject("$match", new BasicDBObject("count",
                                new BasicDBObject("$gt", 2))),
                        new BasicDBObject("$sort", new BasicDBObject("_id", 1))
                );

        int answer = 0;
        for (DBObject doc : output.results()) {
            answer += (Double) doc.get("_id");
        }

        System.out.println("THE ANSWER IS: " + answer);
    }
View Full Code Here

TOP

Related Classes of com.mongodb.AggregationOutput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.