I'm using Motor, which uses pymongo under the hood, to implement pagination for some documents. Here is what I have:
rows = (
db.programs
.find(query)
.sort("_id")
.skip(page * page_count)
.limit(page_count)
)
What's the recommended way to check if there are more documents?
rows.next_object() is always returning None, even when there are more documents to fetch.
You can limit to
page_count+1documents. If you get that many, you know there is another page of results to show. If you getpage_countor fewer, you are on the last page.