couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Goodlad <da...@goodlad.ca>
Subject Re: Order posts by most recently commented on?
Date Thu, 25 Feb 2010 00:24:50 GMT
On Thu, Feb 25, 2010 at 10:34 AM, Travis LaDuke <travisladuke@gmail.com> wrote:
> Hello,
> I'm trying to make a very simple forum, which is like a very simple
> blog, except anyone can start a topic. The other small difference is
> that I need to list topics in order of when they were last replied to
> (commented on) instead of when the topic was created. You know how a
> forum works. I can't figure out any combination of map/reduce/list
> that works. Is it possible? I want to try to make this a standalone
> couchdb app.

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.

Dave

Mime
View raw message