Reputation: 3860
I'm trying to make a pagination system with ranges :
$hospitals=$qb->select('subtype','price','title','date','photos','description')
->field('active')
->equals(1)
->limit(10)
->field('date')
->lte($lastdate)
->sort('_id', 'desc')
->getQuery()
->execute()
->toArray();
Along with this data , I want to send a 'has_more' attribute because I've developed an infinite scroll and it would be meaningless to query data when you're sure it won't return anything.
I want to know how can I get the has_more boolean from the query above.
A way would be to calculate the total number of queries and compare with the limit , but I believe there is some way smarter and easier ..
Upvotes: 1
Views: 284
Reputation: 222621
When I am implementing infinite scroll or pagination with mongo, I am using the following technique (I hope you will be able to adapt it to your doctrine).
If for example I have to show X
elements per scroll/page. I am selecting X+1
element. Then if exactly X+1
element was selected I am selecting new X+1
element (skipping the first X
). But I output always only X
elements.
If you have less than X+1
, I output all of them and know that there is nothing else to show.
Another approach is not to bother with all this +1
thing and only get X
elements and stop right when you encounter an empty result. After this point of time, you just stop sending requests.
Upvotes: 2