/** * All headers except collection and database are non available for this operation. * * @param exchange * @throws Exception */ protected void doAggregate(Exchange exchange) throws Exception { 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); }