Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use mongodb skip() and limit() in meteor?

How to use skip() and limit() in meteor?

Post.find({"user_id":user_id}).skip(0).limit(5);

when I execute above line server says

Exception while invoking method 'Userpost' TypeError: Object [object Object] has no method 'skip'

like image 1000
Ramesh Murugesan Avatar asked May 18 '15 09:05

Ramesh Murugesan


People also ask

How does skip and limit work in MongoDB?

The limit() function in MongoDB is used to specify the maximum number of results to be returned. Only one parameter is required for this function.to return the number of the desired result. Sometimes it is required to return a certain number of results after a certain number of documents. The skip() can do this job.

How does skip work in MongoDB?

In MongoDB, the skip() method will skip the first n document from the query result, you just need to pass the number of records/documents to be skipped. It basically removes the first n documents from the result set.

How do I limit records in MongoDB?

The Limit() Method To limit the records in MongoDB, you need to use limit() method. The method accepts one number type argument, which is the number of documents that you want to be displayed.


2 Answers

You should try putting the skip and limit options as an object parameter within the find() method as follows:

Post.find({"user_id":user_id}, {skip: 0, limit: 5}); 
like image 177
chridam Avatar answered Sep 23 '22 12:09

chridam


Here is the doc about collection.find([selector], [options])

skip and limit are options of the find method

like image 35
Leo Avatar answered Sep 20 '22 12:09

Leo