Reputation: 353
I have a repository with a simple query with pagination :
Page<MyBean> findMyBeans(String name, Pageable pageable);
My question is :
The pagination will limit to 20 (by default) the query to the mongo (like a limit in mysql) or it will retrieve all data from mongo and retun only 20 results to the caller ?
Thanks
Upvotes: 1
Views: 313
Reputation: 16086
It will limit a cursor to 20. Specifically it would create a DBCursor with the value limit to 20 as next:
Cursor id=0, ns=test.myCollection, query={ }, numIterated=0, limit=100, readPreference=primary
This is the same if you use the Java Mongo DB Driver and declares a DBCursor
as:
DBCursor myCursor=myCollection.find().limit(20);
So using MongoDB directly native cursor would be (it iterates in 20 to 20)(First call first 20, then 21-40, and so on):
Cursor cursor = myCollection.find();
cursor.limit(20);
Upvotes: 1