Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding first 20 documents from collection in mongodb

Tags:

mongodb

I want to display first 20 records from collection on one Jframe and next 20 on another frame . I am newbie to MongoDB. please suggest a query to find first 20 and next 20 documents.

like image 635
Prashant Thorat Avatar asked Dec 08 '22 14:12

Prashant Thorat


1 Answers

On the MongoDB shell you can do:

db.collectionName.find( { city: "London" } ).skip( 20 ).limit( 20 );

To show the results from document 21 to 40.

Please look at limit and skip: http://docs.mongodb.org/manual/core/read/#limit-the-number-of-documents-to-return

I also strongly suggest you go over a tutorial: http://docs.mongodb.org/manual/tutorial/getting-started/

like image 108
Derick Avatar answered Feb 01 '23 09:02

Derick