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'
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.
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.
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.
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});
Here is the doc about collection.find([selector], [options])
skip and limit are options of the find method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With