You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Wolfgang Egger <be...@wolfgang-egger.de> on 2010/09/13 17:23:11 UTC

SQL-like-JOINs?

Servus,

I want to show two (or more) Documents combined with one Regquest.
Its like a JOIN in SQL. Is there any way to do that without some kind of
middleware, onl as a "couchapp"?

I would be happy to read about any hint for that!

Have a nice and relaxing day ;)

Wolfgang


Re: SQL-like-JOINs?

Posted by Zsolt Czinkos <cz...@gmail.com>.
Hi

I've found this blog entry:

http://www.cmlenz.net/archives/2007/10/couchdb-joins


Hope this helps.

Zsolt

On Mon, Sep 13, 2010 at 5:23 PM, Wolfgang Egger <be...@wolfgang-egger.de> wrote:
> Servus,
>
> I want to show two (or more) Documents combined with one Regquest.
> Its like a JOIN in SQL. Is there any way to do that without some kind of
> middleware, onl as a "couchapp"?
>
> I would be happy to read about any hint for that!
>
> Have a nice and relaxing day ;)
>
> Wolfgang
>
>

Re: SQL-like-JOINs?

Posted by Stephen Prater <st...@agrussell.com>.
Wolfgang - I think what you need a view over this stuff.

Let say all of these thing assemble "AssemblyA"

The key (for me) was to think of the components as belonging to the  
Assembly, rather than
the Assembly as requiring the components.

here is a very incomplete example:

http://friendpaste.com/33QacbNL5nyGcARNN1TCdk

The overview is to have an array of Assemblies on each component, and  
then emit
a key into a view for each assembly on each component, so for example,  
you'd emit

["AssemblyA","assembly",nil]
["AssemblyA","tool",0]
["AssemblyA","tool",0]
["AssemblyA","part",0]
["AssemblyA","part",0]

you can emit the "teasers" fields in the map based on what "type" of  
document it is, or you can do "include_docs" and get the entire tool.

does that help?

On Sep 13, 2010, at 10:58 AM, Wolfgang Egger wrote:

> Kenneth Tyler <ke...@...> writes:
>
>>
>> Wolfgang,
>> Just like in SQL, the first question is what is common to the two  
>> (or more)
>> documents that you want to combine ?
>> Do they have the same type ? Are they in a certain date range ? Do  
>> they
>> share some other field of information ?
>
>
> There is one MainDocument, that references to some "Sub"-Documents.
>
> Say you have a manual, how to build one thing from three smaller  
> parts.
>
> Somethng like:
> You need:
> Object A
> Object B
> Object C
> You use:
> Tool A
> Tool B
> Tool C
>
> HowTo:
> Put Object A together with Object B by using Tool A upon Object C
> ......
>
> This is the MainDocument.
> Ther are Documents, that describe Object A .. Object C and the  
> Tools, this are
> the "Sub" Documents.
>
> I want to show The MainDocument and e.g. some "Teasers" with a short- 
> description
> of the Tools and Objects together with som links, to the whole
> Description-Documents.
>
> If the Descriptions will change or updated, this changes shoud be  
> reflected ,
> without the need to change them "mqnually" within the MainDocument.
>
> Wolfgang
>
>


Re: SQL-like-JOINs?

Posted by Dave Cottlehuber <da...@muse.net.nz>.
Also a good post on
http://blog.couchone.com/post/446015664/whats-new-in-apache-couchdb-0-11-part-two-views
about this functionality.
dch

On 14 September 2010 04:34, Kenneth Tyler <ke...@8thfold.com> wrote:
> Wolfgang,
> If you look here:
> http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views
> at the topic "linked documents"
> you will see that: "This means that if one document contains the ids of
> other documents, it can cause those documents to be fetched in the view too,
> adjacent to the same key if required."
>
> this means that you can include your sub-document names as a list in your
> main document:
> {
>   "Object List": [
>       "Object A",
>       "Object B"
>   ]
> }
>
> and in your view you can use the names in the object list to pull in the
> document about the object with the additional information. This means that
> you will have to create the reference document with the string "Object A",
> for example,  as its key, rather than a randomly generated key. Then if you
> have to update the additional information for object a, every time the view
> pulls in the "Object A" document it will get the new information.
>
>
>
> so this way your objects and tools are lists in the main document.. and the
> lists include a  name that can be used to pull in the "more information"
> document for each object or tool.
>
> it might help to add a "type" field for the lookup documents for objects and
> tools: {"type":"object"}
> so then you can make a view that will list all the "object" lookup
> documents.
>
> this is a good example of how a problem that needs to be solved with a join
> in sql does not require a join in couchdb...because in couchdb lists can be
> kept in the document itself, rather than the document storing links to other
> records that make up the list.
>
>
> ken tyler
>
> On Mon, Sep 13, 2010 at 8:58 AM, Wolfgang Egger <be...@wolfgang-egger.de>wrote:
>
>> Kenneth Tyler <ke...@...> writes:
>>
>> >
>> > Wolfgang,
>> > Just like in SQL, the first question is what is common to the two (or
>> more)
>> > documents that you want to combine ?
>> > Do they have the same type ? Are they in a certain date range ? Do they
>> > share some other field of information ?
>>
>>
>> There is one MainDocument, that references to some "Sub"-Documents.
>>
>> Say you have a manual, how to build one thing from three smaller parts.
>>
>> Somethng like:
>> You need:
>> Object A
>> Object B
>> Object C
>> You use:
>> Tool A
>> Tool B
>> Tool C
>>
>> HowTo:
>> Put Object A together with Object B by using Tool A upon Object C
>> ......
>>
>> This is the MainDocument.
>> Ther are Documents, that describe Object A .. Object C and the Tools, this
>> are
>> the "Sub" Documents.
>>
>> I want to show The MainDocument and e.g. some "Teasers" with a
>> short-description
>> of the Tools and Objects together with som links, to the whole
>> Description-Documents.
>>
>> If the Descriptions will change or updated, this changes shoud be reflected
>> ,
>> without the need to change them "mqnually" within the MainDocument.
>>
>> Wolfgang
>>
>>
>

Re: SQL-like-JOINs?

Posted by Kenneth Tyler <ke...@8thfold.com>.
Wolfgang,
If you look here:
http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views
at the topic "linked documents"
you will see that: "This means that if one document contains the ids of
other documents, it can cause those documents to be fetched in the view too,
adjacent to the same key if required."

this means that you can include your sub-document names as a list in your
main document:
{
   "Object List": [
       "Object A",
       "Object B"
   ]
}

and in your view you can use the names in the object list to pull in the
document about the object with the additional information. This means that
you will have to create the reference document with the string "Object A",
for example,  as its key, rather than a randomly generated key. Then if you
have to update the additional information for object a, every time the view
pulls in the "Object A" document it will get the new information.



so this way your objects and tools are lists in the main document.. and the
lists include a  name that can be used to pull in the "more information"
document for each object or tool.

it might help to add a "type" field for the lookup documents for objects and
tools: {"type":"object"}
so then you can make a view that will list all the "object" lookup
documents.

this is a good example of how a problem that needs to be solved with a join
in sql does not require a join in couchdb...because in couchdb lists can be
kept in the document itself, rather than the document storing links to other
records that make up the list.


ken tyler

On Mon, Sep 13, 2010 at 8:58 AM, Wolfgang Egger <be...@wolfgang-egger.de>wrote:

> Kenneth Tyler <ke...@...> writes:
>
> >
> > Wolfgang,
> > Just like in SQL, the first question is what is common to the two (or
> more)
> > documents that you want to combine ?
> > Do they have the same type ? Are they in a certain date range ? Do they
> > share some other field of information ?
>
>
> There is one MainDocument, that references to some "Sub"-Documents.
>
> Say you have a manual, how to build one thing from three smaller parts.
>
> Somethng like:
> You need:
> Object A
> Object B
> Object C
> You use:
> Tool A
> Tool B
> Tool C
>
> HowTo:
> Put Object A together with Object B by using Tool A upon Object C
> ......
>
> This is the MainDocument.
> Ther are Documents, that describe Object A .. Object C and the Tools, this
> are
> the "Sub" Documents.
>
> I want to show The MainDocument and e.g. some "Teasers" with a
> short-description
> of the Tools and Objects together with som links, to the whole
> Description-Documents.
>
> If the Descriptions will change or updated, this changes shoud be reflected
> ,
> without the need to change them "mqnually" within the MainDocument.
>
> Wolfgang
>
>

Re: SQL-like-JOINs?

Posted by Wolfgang Egger <be...@wolfgang-egger.de>.
Thanks a lot!!

I will have a deeper look at this "Linked documents"-feature, it seems to be
what I need.



Re: SQL-like-JOINs?

Posted by Wolfgang Egger <be...@wolfgang-egger.de>.
Kenneth Tyler <ke...@...> writes:

> 
> Wolfgang,
> Just like in SQL, the first question is what is common to the two (or more)
> documents that you want to combine ?
> Do they have the same type ? Are they in a certain date range ? Do they
> share some other field of information ?


There is one MainDocument, that references to some "Sub"-Documents.

Say you have a manual, how to build one thing from three smaller parts.

Somethng like:
You need:
Object A
Object B
Object C
You use:
Tool A
Tool B
Tool C

HowTo:
Put Object A together with Object B by using Tool A upon Object C
......

This is the MainDocument.
Ther are Documents, that describe Object A .. Object C and the Tools, this are
the "Sub" Documents.

I want to show The MainDocument and e.g. some "Teasers" with a short-description
of the Tools and Objects together with som links, to the whole
Description-Documents.

If the Descriptions will change or updated, this changes shoud be reflected ,
without the need to change them "mqnually" within the MainDocument.

Wolfgang


Re: SQL-like-JOINs?

Posted by Kenneth Tyler <ke...@8thfold.com>.
Wolfgang,
Just like in SQL, the first question is what is common to the two (or more)
documents that you want to combine ?
Do they have the same type ? Are they in a certain date range ? Do they
share some other field of information ?

Ken Tyler

On Mon, Sep 13, 2010 at 8:23 AM, Wolfgang Egger <be...@wolfgang-egger.de>wrote:

> Servus,
>
> I want to show two (or more) Documents combined with one Regquest.
> Its like a JOIN in SQL. Is there any way to do that without some kind of
> middleware, onl as a "couchapp"?
>
> I would be happy to read about any hint for that!
>
> Have a nice and relaxing day ;)
>
> Wolfgang
>
>

Re: SQL-like-JOINs?

Posted by Dmitry Kurilov <me...@dmkonweb.ru>.
Hi,

I know two ways:
1. http://www.vertigrated.com/blog/2010/04/where-clauses-like-selects-against-couchdb/
2. http://github.com/rnewson/couchdb-lucene

It might help.

2010/9/13 Wolfgang Egger <be...@wolfgang-egger.de>:
> Servus,
>
> I want to show two (or more) Documents combined with one Regquest.
> Its like a JOIN in SQL. Is there any way to do that without some kind of
> middleware, onl as a "couchapp"?
>
> I would be happy to read about any hint for that!
>
> Have a nice and relaxing day ;)
>
> Wolfgang
>
>