Example usage for com.mongodb.client AggregateIterable useCursor

List of usage examples for com.mongodb.client AggregateIterable useCursor

Introduction

In this page you can find the example usage for com.mongodb.client AggregateIterable useCursor.

Prototype

@Deprecated
AggregateIterable<TResult> useCursor(@Nullable Boolean useCursor);

Source Link

Document

Sets whether the server should use a cursor to return results.

Usage

From source file:org.codinjutsu.tools.nosql.mongo.logic.SingleMongoClient.java

License:Apache License

private MongoResult aggregate(MongoQueryOptions mongoQueryOptions, MongoResult mongoResult,
        MongoCollection<Document> collection) {
    AggregateIterable<Document> aggregate = collection.aggregate(mongoQueryOptions.getOperations());
    aggregate.useCursor(true);

    int index = 0;
    MongoCursor<Document> iterator = aggregate.iterator();
    while (iterator.hasNext() && index < mongoQueryOptions.getResultLimit()) {
        mongoResult.add(iterator.next());
    }/*from  w ww. j ava  2s.c  o  m*/
    return mongoResult;
}