You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Andrey Cherkashin <an...@gmail.com> on 2011/09/28 21:05:30 UTC
Make a three
I have a bunch of documents, and I would like to build a three based on data from them. For example I have objects like this:
[{
name: "1",
category: "Paint",
sub_category: "Inside",
brand: "ACME"
},
{
name: "2",
category: "Paint",
sub_category: "Inside",
brand: "ACME"
},
{
name: "asd",
category: "Tools",
sub_category: "Hammer",
brand: "ACME"
},
{
name: "asd",
category: "Tools",
sub_category: "Hammer",
brand: "UY"
},
{
name: "asd",
category: "Paint",
sub_category: "Outside",
brand: "UY"
}]
And I would like to build a three like this:
[ {category: "Paint",
subs: ["Inside", "Outside"],
brands: ["ACME", "UY"]
},
{
category: "Tools",
subs:["Hammer"],
brands: ["ACME", "UY"]
}]
Is it possible to build in inside couch? Or Move it to middleware?
Re: Make a three
Posted by Alexander Gabriel <al...@barbalex.ch>.
yes!
Thanks, Alex
2011/9/29, kowsik <ko...@gmail.com>:
> Does this help?
>
> http://blog.mudynamics.com/2010/10/02/using-couchdb-group_level-for-hierarchical-data/
>
> K.
> ---
> http://blitz.io
> @pcapr
>
> On Wed, Sep 28, 2011 at 12:49 PM, Andrew Cherkashin <an...@gmail.com>
> wrote:
>> Can you provide an example of query?
>>
>> On Wed, Sep 28, 2011 at 12:42 PM, Jens Alfke <je...@couchbase.com> wrote:
>>> If I understand what you’re asking for, you can create a view whose keys
>>> are [category, sub_category, brand]:
>>> function(doc) {emit([doc.category, doc.sub_category, doc.brand],
>>> null);}
>>> Then you can use grouping in queries to get all the subcategories of a
>>> category, or all the brands.
>>>
>>> —Jens
>>
>
--
*****************************************************************
Alexander Gabriel
Wiesenstrasse 22
8800 Thalwil
079/ 372 51 64
alex@barbalex.ch
ww.barbalex.ch
Re: Make a three
Posted by kowsik <ko...@gmail.com>.
Does this help?
http://blog.mudynamics.com/2010/10/02/using-couchdb-group_level-for-hierarchical-data/
K.
---
http://blitz.io
@pcapr
On Wed, Sep 28, 2011 at 12:49 PM, Andrew Cherkashin <an...@gmail.com> wrote:
> Can you provide an example of query?
>
> On Wed, Sep 28, 2011 at 12:42 PM, Jens Alfke <je...@couchbase.com> wrote:
>> If I understand what you’re asking for, you can create a view whose keys are [category, sub_category, brand]:
>> function(doc) {emit([doc.category, doc.sub_category, doc.brand], null);}
>> Then you can use grouping in queries to get all the subcategories of a category, or all the brands.
>>
>> —Jens
>
Re: Make a three
Posted by Andrew Cherkashin <an...@gmail.com>.
Can you provide an example of query?
On Wed, Sep 28, 2011 at 12:42 PM, Jens Alfke <je...@couchbase.com> wrote:
> If I understand what you’re asking for, you can create a view whose keys are [category, sub_category, brand]:
> function(doc) {emit([doc.category, doc.sub_category, doc.brand], null);}
> Then you can use grouping in queries to get all the subcategories of a category, or all the brands.
>
> —Jens
Re: Make a three
Posted by Jens Alfke <je...@couchbase.com>.
If I understand what you’re asking for, you can create a view whose keys are [category, sub_category, brand]:
function(doc) {emit([doc.category, doc.sub_category, doc.brand], null);}
Then you can use grouping in queries to get all the subcategories of a category, or all the brands.
—Jens