Something like;
map;
function(doc) {
emit([doc.name, doc.timestamp], null);
}
no reduce method.
with calls like;
http://localhost:5984/db/_design/ddoc/_view/view?startkey=["name",{}]&endkey=["name"]&descending=true&limit=1
should get you the latest (highest timestamp) for document with
doc.name of "name"
On Thu, Apr 15, 2010 at 11:33 PM, wolfgang haefelinger
<[email protected]> wrote:
> 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
>