Examples of AggregationOutput


Examples of com.mongodb.AggregationOutput

        DBObject query = exchange.getIn().getMandatoryBody(DBObject.class);

        // Impossible with java driver to get the batch size and number to skip
        Iterable<DBObject> dbIterator = null;
        try {
            AggregationOutput aggregationResult = null;

            // Allow body to be a pipeline
            // @see http://docs.mongodb.org/manual/core/aggregation/
            if (query instanceof BasicDBList) {
                BasicDBList queryList = (BasicDBList)query;
                aggregationResult = dbCol.aggregate((DBObject)queryList.get(0), (BasicDBObject[])queryList
                    .subList(1, queryList.size()).toArray(new BasicDBObject[queryList.size() - 1]));
            } else {
                aggregationResult = dbCol.aggregate(query);
            }

            dbIterator = aggregationResult.results();
            Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.aggregate);
            resultMessage.setBody(dbIterator);

            // Mongo Driver does not allow to read size and to paginate aggregate result
        } catch (Exception e) {
View Full Code Here

Examples of com.mongodb.AggregationOutput

        DBCollection dbCol = calculateCollection(exchange);
        DBObject query = exchange.getIn().getMandatoryBody(DBObject.class);

        // Impossible with java driver to get the batch size and number to skip
        Iterable<DBObject> dbIterator = null;
        AggregationOutput aggregationResult = null;

        // Allow body to be a pipeline
        // @see http://docs.mongodb.org/manual/core/aggregation/
        if (query instanceof BasicDBList) {
            BasicDBList queryList = (BasicDBList)query;
            aggregationResult = dbCol.aggregate((DBObject)queryList.get(0), queryList
                .subList(1, queryList.size()).toArray(new BasicDBObject[queryList.size() - 1]));
        } else {
            aggregationResult = dbCol.aggregate(query);
        }

        dbIterator = aggregationResult.results();
        Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.aggregate);
        resultMessage.setBody(dbIterator);
    }
View Full Code Here

Examples of com.mongodb.AggregationOutput

                try {
                    Template helloTemplate = configuration.getTemplate("answer.ftl");

                    // 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("$lte", 2))),
                                    new BasicDBObject("$sort", new BasicDBObject("_id", 1))
                            );

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

                    Map<String, String> answerMap = new HashMap<String, String>();
                    answerMap.put("answer", Integer.toString(answer));
View Full Code Here

Examples of com.mongodb.AggregationOutput

        // Finally the $sort operation
        DBObject sort = new BasicDBObject("$sort", new BasicDBObject("average", -1));

        // run aggregation
        List<DBObject> pipeline = Arrays.asList(match, project, group, sort);
        AggregationOutput output = coll.aggregate(pipeline);

        // Output the results
        for (DBObject result : output.results()) {
            System.out.println(result);
        }

        // Aggregation Cursor
        AggregationOptions aggregationOptions = AggregationOptions.builder()
View Full Code Here

Examples of com.mongodb.AggregationOutput

        DBObject query = exchange.getIn().getMandatoryBody(DBObject.class);

        // Impossible with java driver to get the batch size and number to skip
        Iterable<DBObject> dbIterator = null;
        try {
            AggregationOutput aggregationResult = null;

            // Allow body to be a pipeline
            // @see http://docs.mongodb.org/manual/core/aggregation/
            if (query instanceof BasicDBList) {
                BasicDBList queryList = (BasicDBList)query;
                aggregationResult = dbCol.aggregate((DBObject)queryList.get(0), queryList
                    .subList(1, queryList.size()).toArray(new BasicDBObject[queryList.size() - 1]));
            } else {
                aggregationResult = dbCol.aggregate(query);
            }

            dbIterator = aggregationResult.results();
            Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.aggregate);
            resultMessage.setBody(dbIterator);

            // Mongo Driver does not allow to read size and to paginate aggregate result
        } catch (Exception e) {
View Full Code Here

Examples of com.mongodb.AggregationOutput

   */
  @Override
  public List<String> listCategories() {
    BasicDBObject group = new BasicDBObject("$group", new BasicDBObject(
        "_id", "$category"));
    AggregationOutput aggregate = productCollection.aggregate(group);
    List<String> categories = new ArrayList<>();

    for (DBObject resultObject : aggregate.results()) {
      categories.add((String) resultObject.get("_id"));
    }

    return categories;
  }
View Full Code Here

Examples of com.mongodb.AggregationOutput

    @Test
    public void articleTagToAuthorTest() {
        String testName = "articleTagToAuthorTest";
        DBCollection collection = getCollection(testName);
        insertArticle1(collection);
        AggregationOutput output = AggregateBuilder.aggregate(collection)
            .project(new BasicDBObject()
                    .append("author", 1)
                    .append("tags", 1))
            .unwind("$tags")
            .group(GroupBuilder.start()
View Full Code Here

Examples of com.mongodb.AggregationOutput

    @Test
    public void articleTagToAuthorWithoutLibraryTest() {
        String testName = "articleTagToAuthorTest";
        DBCollection collection = getCollection(testName);
        insertArticle1(collection);
        AggregationOutput output = collection.aggregate(
            new BasicDBObject("$project", new BasicDBObject()
                .append("author", 1)
                .append("tags", 1)
            ),
            new BasicDBObject("$unwind", "$tags"),
View Full Code Here

Examples of com.mongodb.AggregationOutput

    @Test
    public void projectIncludeTest() {
        String testName = "projectIncludeTest";
        DBCollection collection = getCollection(testName);
        insertArticle1(collection);
        AggregationOutput output = AggregateBuilder.aggregate(collection)
                .project(DBO.of("title", 1, "author", 1))
                .run();
        verifyAggregationOutputFromResources(testName, output);
    }
View Full Code Here

Examples of com.mongodb.AggregationOutput

    @Test
    public void projectExcludeIdTest() {
        String testName = "projectExcludeIdTest";
        DBCollection collection = getCollection(testName);
        insertArticle1(collection);
        AggregationOutput output = AggregateBuilder.aggregate(collection)
                .project(DBO.of("_id", 0, "title", 1, "author", 1))
                .run();
        verifyAggregationOutputFromResources(testName, output);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.