couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wolfgang haefelinger <whaefelin...@gmail.com>
Subject getting most recent doc
Date Thu, 15 Apr 2010 22:33:59 GMT
My apologies for asking a probably rather stupid question ..

Docs in my database are events. An event has a category name, a time
stamp and lots of other details. I am looking for the most recent
event.

I started with something like

function (doc) {              // map
  emit(doc.name,doc)
}

function (ks,vs,rr) {
  var maxdoc = max_timestamp(vs);
  return maxdoc;
}

Although I'm reducing considerably, couchdb complains that I'm not
reducing hard enough :-)

(* Btw, what is actually the "reduce" limit? Do attachments count as well?  *)

Then I tried something like

function (doc) {
  emit(doc.name,{ "_id" : doc._id, "ts" : doc.timestamp});
}

and with a "virtually" unchanged reduce function. Now I'm below
couchdb's reduction limit. However, this view does not return the most
recent document I was looking for but the "id" of that document.

I had some hope that query parameter "include_docs=true" would do the
magic (that's why I used "_id" as property name). But then I learned
that "include_docs" is not supported for "reduced" views which took me
by surprise. What could be the rational for this behaviour?

In summary:
* Is there a way to get the "most recent" document via a view?

// Regards

Mime
View raw message