简体   繁体   中英

Creating a MongoDB 'find' query to search between a specific number of matching documents

I am using the MongoDB NodeJS driver and need to search the database for a specific set of posts. However if the post count gets too big I want to search between perhaps the 50th - 100th set of matching posts with the query and return the value to the client. However would searching for so many documents and returning them serve as a performance issue? If so what would be the proper query term?

Sample using skip/limit:

//1st part    
db.dummy.find().limit(10)
//2nd part
db.dummy.find().skip(10).limit(10)

Take a look at the mongodb documentation: http://docs.mongodb.org/manual/reference/method/db.collection.find/

limit: http://docs.mongodb.org/manual/reference/method/cursor.limit/#cursor.limit

skip: http://docs.mongodb.org/manual/reference/method/cursor.skip/#cursor.skip

You can use Skip and limit skip the first 49 objects , then limit it by 50 then you will get what you want !

I hope this will help you ,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM