top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

MongoDB: What is the use of limit and skip method ?

0 votes
490 views
MongoDB: What is the use of limit and skip method ?
posted Jun 26, 2015 by Ganesh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

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"}
answer Jun 27, 2015 by Prakash Singh
Nicely explained .
Similar Questions
+2 votes

Is there a way to configure/increase the memory limit(100MB) on the pipeline? What if I have a lot of RAM that can be used by MongoDB?

+1 vote

We are using mongo DB in a single node. I understand that this is not MongoDB is intended to do. But due to the sophistication of mongos querying and other architectural/ business reasons we have chosen MongoDB. We are facing an issue now. We would be happy to get it resolved with your help.

Problem:
We have to limit the memory utilization of MongoDB.

ENV:
WindowsVersion: 3.2

What we know:
1. MongoDB utilizes as much memory as possible to give a better performance
2. When memory utilization reaches a certain threshold percentage, MongoDB frees up the memory it holds
3. We are not able to see the memory utilization of MongoDB service in Task Manager

+2 votes

Please tell me how can we resolve this issue, we are using aggregation and size of docs become greater than 16MB. We also tried "ALLOWDISKUSE = TRUE" but still its throwing same error.

We are using php to fetch data greater than 16MB. Let me know if you needed more info.

...