I've a wpf app and mongo db as back end, if i call a query to mongo db from wpf app it giving me million of records so currently i'm using normal pagination like storing all data from db into data table and doing pagination. But if system having less memory its impossible to store that much of records, so some body says to me that mongo db provides pagination means we can call records directly from db when user clicks next or previous so any one help me to do this.
Asked
Active
Viewed 875 times
2 Answers
1
You can use mongodb's limit() and skip() to implement paging. For example, to get the 3rd page where page size is 10, you'd use this query:
db.your_collection.find().skip(20).limit(10)

milan
- 11,872
- 3
- 42
- 49
1
There are two kinds of paging:
Via range query:
db.items.find({created: {$gt: startDate, $lt: endDate})
Range queries will work faster then skip, because they are no need to move towards 'skip' item.
Look into related thread as well.
For your case if you have only next/prev buttons range paging should be good option.

Community
- 1
- 1

Andrew Orsich
- 52,935
- 16
- 139
- 134
-
can you plz provide me sample for range paging. – nag Jan 11 '12 at 10:06
-
@nag: see mongo shell example in my answer above. – Andrew Orsich Jan 11 '12 at 10:33