Why is couchrest turning off my reduce function?

1 view
Skip to first unread message

John Griffin

unread,
Dec 7, 2009, 3:54:01 PM12/7/09
to CouchRest
Every time I attempt to use a reduce in my model couch rest seems to
insert "couchrest-defaults": { "reduce": false } into my view. Any
ideas what this means?

Thanks for your help!

Matt Aimonetti

unread,
Dec 7, 2009, 4:05:12 PM12/7/09
to couc...@googlegroups.com
how do you call your reduce function?

- Matt


--

You received this message because you are subscribed to the Google Groups "CouchRest" group.
To post to this group, send email to couc...@googlegroups.com.
To unsubscribe from this group, send email to couchrest+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/couchrest?hl=en.



John Griffin

unread,
Dec 7, 2009, 4:13:06 PM12/7/09
to CouchRest
view_by :most_recent, :map => "function(doc) {emit('date', Date.parse
(doc.created_at));}", :reduce => "function(keys, values, rereduce)
{var rv = null;for (i=0; i<values.length; ++i) {var value = values
[i];rv = Math.max(value, rv || value);}return rv;}"

Thanks Matt

On Dec 7, 9:05 pm, Matt Aimonetti <mattaimone...@gmail.com> wrote:
> how do you call your reduce function?
>
> - Matt
>
>
>
> On Mon, Dec 7, 2009 at 12:54 PM, John Griffin <joh...@gmail.com> wrote:
> > Every time I attempt to use a reduce in my model couch rest seems to
> > insert "couchrest-defaults": { "reduce": false } into my view. Any
> > ideas what this means?
>
> > Thanks for your help!
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "CouchRest" group.
> > To post to this group, send email to couc...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > couchrest+...@googlegroups.com<couchrest%2Bunsubscribe@googlegroups .com>
> > .

Matt Aimonetti

unread,
Dec 7, 2009, 4:19:00 PM12/7/09
to couc...@googlegroups.com
This is how you define your view, but you need to show me how you call it.

For instance:

YourModel.most_recent(:key => today, :reduce => true)

If you don't set the reduce flag, couchrest defaults to the map function being returned.

- Matt

To unsubscribe from this group, send email to couchrest+...@googlegroups.com.

John Griffin

unread,
Dec 7, 2009, 4:27:14 PM12/7/09
to couc...@googlegroups.com
Yep that was it, needed to pass the reduce flag. Thanks for your help, I wasn't aware that was the default behaviour.

John

Matt Aimonetti

unread,
Dec 7, 2009, 5:08:29 PM12/7/09
to couc...@googlegroups.com
no worries, that just proves the documentation isn't good enough :)

- Matt
Reply all
Reply to author
Forward
0 new messages