The Limit method of mongoDB is used to limit the number of records. it accepts the number as argument.
db.mycol.find()
it shows the following list of all the document in mycol collection.
{ "_id" : ObjectId(5383548781331adf45ec1), "title":"MongoDB"}
{ "_id" : ObjectId(5383548781331adf45ec2), "title":"NoSQL"}
{ "_id" : ObjectId(5383548781331adf45ec3), "title":"QueryHome Overview"}
Now i execute the limit method which limits the no. of document to display as follows.
db.mycol.find({}, {"title" : "1", _id : 0}).limit(2)
it will shows the only two documents from the first.
{"title":"MongoDB"}
{"title":"NoSQL"}
The skip() method is used to skip the documents in the mongoDB. it also accepts the number as argument.
db.mycol.find({}, {"title" : "1", _id : 0}).limit(2).skip(1)
it skips the one document from the first and it will show the second document from the collection.
{"title":"NoSQL"}