How to do pagination using mongoengine?

I have a pagination question using mongodb and mongoengine. I have a table that will have millions of records in the future. and I do paging like this.

Well I'm not sure this is the right approach

list = Books.objects.all() paginator = DiggPaginator(list, 20, body = 10, tail = 2) 

here I open the whole table, and then paginate, and again on the next page above the code, we launch and bring the 2nd or any page.

Is this the right approach or are there any better ways to do this.

+6
source share
2 answers

You can use skip and limit from QuerySet to achieve pagination.
For example, if you want to display a second page with a limit of 10 elements per page, you can do this as follows:

 page_nb = 2 items_per_page = 10 offset = (page_nb - 1) * items_per_page list = Books.objects.skip( offset ).limit( items_per_page ) 
+16
source

The flask-mongoengine plugin provides a paginator example , you can adapt to follow the digg pointer.

0
source

All Articles