incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wolfgang haefelinger <>
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

I started with something like

function (doc) {              // map

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(,{ "_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

View raw message