2. PAGINATION
Using 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 and
more CPU intensive. With larger collections,
cursor.skip() may become IO bound.
3. PAGINATION
With Query
Arrange in ascending or descending order
anish 31
manisha 29
…………
Paul 26……..
……………
…….
arjun 8
>var pageCursor = db.user.find().sort({"age":-
1}).limit(10000)
Step 2 : iterate over the cursor
while (pageCursor.hasNext()) {
paul = 26
}
Start with paul age and form the next query and
sort it again