I think you want to be using .skip().limit() (and don't alter your original query you used to get Page #1).
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
On Sat, Apr 2, 2011 at 8:29 AM, Scott Hernandez
<scotthe...@gmail.com> wrote:
> You must include both the ProductName and id in your query; the id
> part will make sure you don't get dups. Also, you must sort on that
See how your query still only has one criteria, the ProductName?
{a:1, b:1}
{a:2, b:1}
{a:2, b:2}
{a:2, b:3}
{a:3, b:1}
So you do this for the range based pagination (page size of 2):
find().sort({a:1, b:1}).limit(2)
{a:1, b:1}
{a:2, b:1}
find({a:{$gt:2}, b:{$gt:1}}).sort({a:1, b:1}).limit(2)
{a:2, b:2}
{a:2, b:3}
find({a:{$gt:2}, b:{$gt:3}}).sort({a:1, b:1}).limit(2)
{a:3, b:1}
You use the previous values for the next page of data, and the start
values for previous page. You can also use a hybrid solution with
ranges and skips which will be much faster than just using skip when
you have an index.
Make sense?
On Sat, Apr 2, 2011 at 12:25 PM, Donny V. <don...@gmail.com> wrote:
> I'm not sure what that looks like in the query.
> Can you give me an example using my query?
>
On Sat, Apr 2, 2011 at 7:58 PM, Donny V. <don...@gmail.com> wrote:
> Sorry I have 1 more question.
>
> Is there a way to jump directly to a page using these range queries?
> Like jump right to page 3.
Generally people search, and want to look at a very small number of
results; the first 3 pages get 99% of the clicks or something like
that.
In fact, when you get to very scalable pagination where one might want
to go to the end of the results, really that just means you want to
reverse the sort and move in that direction.
I would suggest testing and see how usable the system is before going
too much farther, but that is just my 2c.