Mongo db pagination

115 views

Published on

Visit
http://www.zariga.com
http://www.youtube.com/user/zarigatongy

1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total views
115
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Mongo db pagination

  1. 1. MongoDB PAGINATIONPAGINATION detailed
  2. 2. PAGINATIONUsing limit() & skip()Reference :MongoDB(http://docs.mongodb.org/manual/reference/method/cursor.skip/)function printStudents(pageNumber, nPerPage) {print("Page: " + pageNumber);db.students.find().skip((pageNumber-1)*nPerPage).limit(nPerPage).forEach(function(student) { print(student.name + "<p>"); } ); }CONS : cursor.skip() will become slower andmore CPU intensive. With larger collections,cursor.skip() may become IO bound.
  3. 3. PAGINATIONWith QueryArrange in ascending or descending orderanish 31manisha 29…………Paul 26……..………………….arjun 8>var pageCursor = db.user.find().sort({"age":-1}).limit(10000)Step 2 : iterate over the cursorwhile (pageCursor.hasNext()) {paul = 26}Start with paul age and form the next query andsort it again
  4. 4. More Advanced querieshttp://docs.mongodb.org/manual/reference/operators/#AdvancedQueries-
  5. 5. Thanks for Watchingfeedbackappreciated…………………………

×