Thanks yet again Randall, a simple group_level=1 worked. Cheers Mate
From: Randall Leeds <[email protected]> To: [email protected] Date: 02/06/2010 03:45 PM Subject: Re: How do I SUM(values in a field array) using Views Futon uses ?group=true. Check out the group and group_level query string arguments. On Tue, Jun 1, 2010 at 22:38, <[email protected]> wrote: > Hi say I had product documents that looked like this (formatted for > readability): > > { > "_id":"p9", > "_rev":"2-9a109fb7d9f116441876e0d6401ec1ba", > "product_name":"Apple iPhone 3Gs 32GB", > "Stores":[ > { > "name":"Store A", > "item_count":558 > }, > { > "name":"CompuShop", > "item_count":4878 > }, > { > "name":"Kerry's Computer Shop", > "item_count":54474 > } > ] > } > > and a view function: > function(doc) > { > for (id in doc.Stores) > { > if(doc.product_name && doc.Stores[id].item_count) > { > emit(doc.product_name, doc.Stores[id].item_count); > } > } > } > > and a reduce function: > function(keys, values) { > return sum(values); > } > > Why, when I look at the resulting view in Futon does it look correct but > when I view in browser it gives me a null key and a total of all items as > opposed to one for each product? Or if I specify a product using ?key= , > why do i still get key:null > > .../_design/inventory/_view/total_items > {"rows":[ > {"key":null,"value":8452613} > ]} > >
