incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luke Randall <>
Subject Re: Howto drop rows with reduce?
Date Wed, 29 Apr 2009 17:43:09 GMT
Jurg van Vliet wrote:
> if i don't emit anything in the last emit statement i get comments for all of my document
types. then case i end up with a list of articles and comments, both with a comment count.

Hi Jurg

>From what I understand of your situation, I don't see why what Paul
suggested wouldn't work. If you have the following as your map

function(doc) {
    if( doc.type == 'Article') {
        emit( doc._id, 0);
    } else if( doc.type == 'Comment') {
        emit( doc.path[0], 1);

when you reduce it* you will have a list of articles with a comment
count. Note that you there is no requirement to call emit for each
document. If you don't want a document to appear in a view then just
don't call emit on it. Reduce isn't meant to be used as a filter,
that's what map is for.

* Remember to add :group => true to your couchrest view call, as Futon
silently adds it, but it otherwise defaults to being false.

Sorry, this is basically a rehash of what Paul said, but it seems that
you possibly misunderstood his suggestion. Either that or I
misunderstood your reply, which is also quite possible... :)

- Luke

PS Sorry if this message breaks threading; I wasn't subscribed to the
list, so I had to copy and paste this.

View raw message