Closed timzaak closed 8 years ago
The cursor or iterator can fetch new data from the server if needed and discard already consumed data. While a list holds all entries in memory, you can run out of memory when using a list, especially with large result sets.
What Christian said is exactly what the cursor is good for. But if you still need a List you can call cursor.asListRemaining()
to get all remaining result from you query in a List.
This method simple iterates over the cursor and fills a new List.
yes, when the result sets is big, the memory will become a problem. but sometimes, people will use limit
( just like paginate) to make the result size small enough. I think it may improve the efficiency when sending the small result to the client in one response.
This already happen. There is a batchSize which controls how many documents are send in one response. The default in the server is higher then 1 :-).
You can also set it in the driver call for a single query:
ArangoCursor<BaseDocument> cursor = arangoDB.db().query("your query", null, new AqlQueryOptions().batchSize(100000), BaseDocument.class);
List<BaseDocument> resultAsList = cursor.asListRemaining();
@mpv1989 thanks very match.
I find it will send a request to db if I call the
cursor.next()
method, if it possible to return all the result as Collection(List), or make it configurable to decide which one to return?