You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Rory Franklin <ro...@chillibean.tv> on 2012/06/11 12:29:19 UTC
Reducing/Grouping an array
Hi,
Is it possible to have a view that emits out something like the following:
("key1", [1,1,0,1])
("key1", [1,1,1,0])
("key1", [1,0,0,0])
("key2", [0,1,0,0])
which can be grouped to the following:
"key1", [3,2,1,1]
"key2", [0,1,0,0]
Or would this calculation have to be made in the application layer?
Thanks,
Rory
Re: Reducing/Grouping an array
Posted by Rory Franklin <ro...@chillibean.tv>.
Thanks to both of you for the answer (sorry for my delayed reply!) - it works like a charm! Is this something that has appeared in recent versions of Couch? We had a database running on 1.0.1 that this didn't work on (upgrading to 1.2 fixed it though).
Rory
On Monday, 11 June 2012 at 18:58, Mark Hahn wrote:
> map-reduce works on all types of obects or even lists of types
>
> On Mon, Jun 11, 2012 at 3:39 AM, Robert Newson <robert.newson@gmail.com (mailto:robert.newson@gmail.com)>wrote:
>
> > Sure, the built-in _sum reduce function works for lists of numbers too.
> >
> > B.
> >
> > On 11 Jun 2012, at 11:29, Rory Franklin wrote:
> >
> > > Hi,
> > >
> > > Is it possible to have a view that emits out something like the
> > following:
> > >
> > > ("key1", [1,1,0,1])
> > > ("key1", [1,1,1,0])
> > > ("key1", [1,0,0,0])
> > > ("key2", [0,1,0,0])
> > >
> > > which can be grouped to the following:
> > >
> > > "key1", [3,2,1,1]
> > > "key2", [0,1,0,0]
> > >
> > >
> > > Or would this calculation have to be made in the application layer?
> > >
> > >
> > > Thanks,
> > > Rory
> > >
> >
> >
>
>
>
Re: Reducing/Grouping an array
Posted by Mark Hahn <ma...@hahnca.com>.
map-reduce works on all types of obects or even lists of types
On Mon, Jun 11, 2012 at 3:39 AM, Robert Newson <ro...@gmail.com>wrote:
> Sure, the built-in _sum reduce function works for lists of numbers too.
>
> B.
>
> On 11 Jun 2012, at 11:29, Rory Franklin wrote:
>
> > Hi,
> >
> > Is it possible to have a view that emits out something like the
> following:
> >
> > ("key1", [1,1,0,1])
> > ("key1", [1,1,1,0])
> > ("key1", [1,0,0,0])
> > ("key2", [0,1,0,0])
> >
> > which can be grouped to the following:
> >
> > "key1", [3,2,1,1]
> > "key2", [0,1,0,0]
> >
> >
> > Or would this calculation have to be made in the application layer?
> >
> >
> > Thanks,
> > Rory
>
>
Re: Reducing/Grouping an array
Posted by Robert Newson <ro...@gmail.com>.
Sure, the built-in _sum reduce function works for lists of numbers too.
B.
On 11 Jun 2012, at 11:29, Rory Franklin wrote:
> Hi,
>
> Is it possible to have a view that emits out something like the following:
>
> ("key1", [1,1,0,1])
> ("key1", [1,1,1,0])
> ("key1", [1,0,0,0])
> ("key2", [0,1,0,0])
>
> which can be grouped to the following:
>
> "key1", [3,2,1,1]
> "key2", [0,1,0,0]
>
>
> Or would this calculation have to be made in the application layer?
>
>
> Thanks,
> Rory