advice for paging collections

40 views
Skip to first unread message

Pierre Guillaume Herveou

unread,
Apr 25, 2012, 11:09:28 AM4/25/12
to mongod...@googlegroups.com
Hi guys, I need your advice for different kind of pagings

I need to implement paging for something similar to a twitter list of message in my app. I don't expect user to scroll more than 3, 4 pages in normal usage.
What do you advice for this kind of paging. I read on the doc that skip() could be quite slow for large collection

I have also another kind of paging where user can perform a query on a certain type of collection (e.g collection of user filtered by user name) and I need to page this results as well. 
I don't expect queries to return more than 1000 or so document but I need to page them 10 by 10 on the app
What would be appropriate as well for this kind of paging ?

Sam Millman

unread,
Apr 25, 2012, 11:13:51 AM4/25/12
to mongod...@googlegroups.com
Time ranges. Twitter and fb both use time range paging for their feeds, so you say sort by time desc and then limit by 20 and then get the ts of the last object and use that as the skip range for the next 20. It works well.

But skip() will be no problem on 1000 documents what it means by skip being slow is when you start paging 1000000 documents.

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-user/-/PMy_pWAxLDYJ.
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.

Pierre Guillaume Herveou

unread,
Apr 25, 2012, 2:22:45 PM4/25/12
to mongod...@googlegroups.com
Thks for your help

so for the feed query you would do something like that right ?

db.feeds.find({ "time": {$lt: lastFeed.time} }).sort( { time : -1 } ).limit(20)



To unsubscribe from this group, send email to mongodb-user+unsubscribe@googlegroups.com.

Sam Millman

unread,
Apr 25, 2012, 2:40:42 PM4/25/12
to mongod...@googlegroups.com
Indeed

To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-user/-/atVoGpBIbA4J.

To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages