1

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.

brunnerh
188k30 gold badges363 silver badges434 bronze badges
asked Jan 10, 2012 at 10:34

2 Answers 2

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)
answered Jan 10, 2012 at 15:02
Sign up to request clarification or add additional context in comments.

Comments

1

There are two kinds of paging:

  1. Via limit and skip, just like @milan proposed.

  2. 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.

answered Jan 11, 2012 at 8:29

2 Comments

can you plz provide me sample for range paging.
@nag: see mongo shell example in my answer above.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.