Couch just doesn't handle this well. You can either reduce to the last comment date for each topic and sort application-side, or you can go update the topic document. One good thing if you choose the latter: if you stipulate that updating the topic always updates the "lastCommentDate," then you can ignore write failures due to outdated revs.
A On Wed, Feb 24, 2010 at 4:49 PM, Travis LaDuke <[email protected]>wrote: > On Wed, Feb 24, 2010 at 4:24 PM, David Goodlad <[email protected]> wrote: > > If you have comments stored as individual docs, with an associated > > topic doc on each, you could use a map function like: > > > > function(doc) { > > if(doc.type == 'comment') { > > emit(doc.post_time, {"id": doc.topic_id}); > > } > > } > > > > You could then query that view with include_docs=true to get all the > > topics sorted by comments' post times. You'd probably want a list > > function that would remove duplicates, since each topic would be > > included in the view once per comment in that topic. > > > > Thanks, I didn't know about include_docs. I had thought of this before > (without the include_docs), but gave up when I thought it would make > it hard to paginate. If I say like limit 10, and there's a thread with > 10 comments, I'll only get one topic in the list. Is there a way? >
