I am Hack Sparrow
Captain of the Internets.

MongoDB Pagination – using $slice

Another technique of implementing pagination in MongoDB involves the use of $push and $slice. In this method, we store the documents in an array and use the $slice method to accomplish what skip()-and-limit() does, but without the overhead associated with the skip() method. We will be using a single root document in a collection with two fields: i. an arr ...

MongoDB Pagination – using range queries

This method of MongoDB pagination requires manually setting the _id field in your documents. It uses the min() and max() MongoDB cursor functions to implement the pagination. We'll be learning by examples on a collection named 'companies'. Make sure there are no documents on it. [code] db.companies.remove() [/code] Make sure the _id value starts from 0 and increment ...

MongoDB Pagination – using skip()

Curious how pagination might be implemented in MongoDB? Let's have a data set to play around with so that we can learn by examples. Create a collection named companies and add some documents on it. [code] db.companies.insert({name:'Google'}) db.companies.insert({name:'Facebook'}) db.companies.insert({name:'Apple'}) db.companies.insert({name:'Microsoft'}) db.companies.insert({name:'Oracle'}) db.companies.insert ...