use of com.mongodb.client.internal.MongoBatchCursorAdapter in project mongo-java-driver by mongodb.
the class DBCollection method aggregate.
/**
* Method implements aggregation framework.
*
* @param pipeline operations to be performed in the aggregation pipeline
* @param options options to apply to the aggregation
* @param readPreference {@link ReadPreference} to be used for this operation
* @return the aggregation operation's result set
* @mongodb.driver.manual core/aggregation-pipeline/ Aggregation
* @mongodb.server.release 2.2
*/
public Cursor aggregate(final List<? extends DBObject> pipeline, final AggregationOptions options, final ReadPreference readPreference) {
Cursor result;
notNull("options", options);
List<BsonDocument> stages = preparePipeline(pipeline);
BsonValue outCollection = stages.get(stages.size() - 1).get("$out");
if (outCollection != null) {
AggregateToCollectionOperation operation = new AggregateToCollectionOperation(getNamespace(), stages, getReadConcern(), getWriteConcern()).maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS).allowDiskUse(options.getAllowDiskUse()).bypassDocumentValidation(options.getBypassDocumentValidation()).collation(options.getCollation());
try {
executor.execute(operation, getReadPreference(), getReadConcern());
result = new DBCursor(database.getCollection(outCollection.asString().getValue()), new BasicDBObject(), new DBCollectionFindOptions().readPreference(primary()).collation(options.getCollation()));
} catch (MongoWriteConcernException e) {
throw createWriteConcernException(e);
}
} else {
AggregateOperation<DBObject> operation = new AggregateOperation<DBObject>(getNamespace(), stages, getDefaultDBObjectCodec()).maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS).allowDiskUse(options.getAllowDiskUse()).batchSize(options.getBatchSize()).collation(options.getCollation()).retryReads(retryReads);
BatchCursor<DBObject> cursor1 = executor.execute(operation, readPreference, getReadConcern());
result = new MongoCursorAdapter(new MongoBatchCursorAdapter<DBObject>(cursor1));
}
return result;
}
Aggregations