Hi Sam,

I would have 2 further tips:

1.  I would go further and say: Never emit the full doc in a map function.
You can get the full doc by using the include_docs flag when querying the
view. If you need a key that only refers to a single doc, use the _id of
the doc.

2.  Don't write your own reduce functions, use couch's built in, erlang
functions (See http://wiki.apache.org/couchdb/Built-In_Reduce_Functions).
You will save yourself a lot of headaches and you will not match the
performance of these functions. In your case, _count is probably what you
want, though you probably don't even need a reduce function with such an
index (as Aurelien essentially pointed out). Handle the case where
doc.tweets doesn't exist in your map function:

emit(doc._id, doc.tweets || []);

Cheers,
Mike



Am Sonntag, 30. November 2014 schrieb Aurélien Bénel :

> Hi Sam,
>
> > # map function
> > function(doc) {
> >  emit(doc, doc.tweets);
> > }
>
> Your map function is really weird.
>
> Think of `map` as a way to create secondary indexes.
>
> 1. An index on the whole document doesn't make much sense.
> 2. Moreover, at query time, if you want to get data that are in the same
> document,
> you don't need map/reduce at all. Just create a `show` function.
>
>
> Regards,
>
> Aurélien

Reply via email to