how to work on multiple databases

285 views
Skip to first unread message

go canal

unread,
Sep 22, 2009, 10:51:00 PM9/22/09
to us...@couchdb.apache.org
Hello,
I am only one-day 'old' in the Couch world, CouchDB is really cool :-)
I have a lot of questions though, sorry if these had been already answered...

Are there APIs available for working on multiple databases ?

Here is the use case/data model:
* a CouchDB database for one project
all project related documents are stored in the DB.
* a user can participate in multiple projects

let's say a user wants to display a list of his documents in all projects, how do we support this ? Do I have to issue one query command for each database then aggregate the result ?

thanks
canal

Nadav Samet

unread,
Sep 22, 2009, 11:03:58 PM9/22/09
to us...@couchdb.apache.org
The HTTP API works against one database at a time (at one http server). All
libraries I have seen will let you talk to multiple databases, but don't
have any functionality to send a single query to several databases and
aggregate the results. (This kind of functionality is too
application-specific to be in a general purpose library.)


--
Sincerely yours,
Nadav

Chris Anderson

unread,
Sep 23, 2009, 1:29:36 AM9/23/09
to us...@couchdb.apache.org
On Tue, Sep 22, 2009 at 8:03 PM, Nadav Samet <thes...@gmail.com> wrote:
> The HTTP API works against one database at a time (at one http server). All
> libraries I have seen will let you talk to multiple databases, but don't
> have any functionality to send a single query to several databases and
> aggregate the results. (This kind of functionality is too
> application-specific to be in a general purpose library.)

The CouchDB-Lounge project has a query merging proxy which could be
adapted for this purpose.

> On Tue, Sep 22, 2009 at 7:51 PM, go canal <goc...@yahoo.com> wrote:
>
>> Hello,
>> I am only one-day 'old' in the Couch world, CouchDB is really cool :-)
>> I have a lot of questions though, sorry if these had been already
>> answered...
>>
>> Are there APIs available for working on multiple databases ?
>>
>> Here is the use case/data model:
>>  * a CouchDB database for one project
>>    all project related documents are stored in the DB.
>>  * a user can participate in multiple projects
>>
>> let's say a user wants to display a list of his documents in all projects,
>> how do we support this ? Do I have to issue one query command for each
>> database then aggregate the result ?
>>
>> thanks
>> canal
>>
>>
>>
>>
>
>
>
>
> --
> Sincerely yours,
> Nadav
>

--
Chris Anderson
http://jchrisa.net
http://couch.io

go canal

unread,
Sep 23, 2009, 5:46:06 AM9/23/09
to us...@couchdb.apache.org
thanks for a quick response.

I agree that the use case is application specific; however, I tend to think that the data model is actually generic.

I do not know the design intent of a 'database' in CouchDB. For performance reason, and/or other something else. But I thought that since we have an API for getting all DBs, we might have something else for developers to manage a groups DBs.

rgds,
canal


________________________________
From: Nadav Samet <thes...@gmail.com>
To: us...@couchdb.apache.org
Sent: Wednesday, September 23, 2009 11:03:58 AM
Subject: Re: how to work on multiple databases

go canal

unread,
Sep 23, 2009, 5:55:46 AM9/23/09
to us...@couchdb.apache.org
thanks.
I quickly google, saw two lounge projects. guess this one is for the partitioning solution ? That's very good, I am about to ask this feature .....

Is there a plan to merge this into CouchDB core ?

rgds,
canal


________________________________
From: Chris Anderson <jch...@apache.org>
To: us...@couchdb.apache.org
Sent: Wednesday, September 23, 2009 1:29:36 PM


Subject: Re: how to work on multiple databases

On Tue, Sep 22, 2009 at 8:03 PM, Nadav Samet <thes...@gmail.com> wrote:

Adam Kocoloski

unread,
Sep 23, 2009, 7:42:01 AM9/23/09
to us...@couchdb.apache.org
On Sep 23, 2009, at 5:55 AM, go canal wrote:

> thanks.
> I quickly google, saw two lounge projects. guess this one is for the
> partitioning solution ? That's very good, I am about to ask this
> feature .....
>
> Is there a plan to merge this into CouchDB core ?

Yes, CouchDB will definitely have partitioning, either via Lounge or
an all-Erlang solution. Best,

Adam

go canal

unread,
Sep 23, 2009, 8:17:43 PM9/23/09
to us...@couchdb.apache.org
that's really good news. hope it will be available for a projet I am working on now (to be delivered sometime around next June)
 rgds,
canal


________________________________
From: Adam Kocoloski <koco...@apache.org>
To: us...@couchdb.apache.org
Sent: Wednesday, September 23, 2009 7:42:01 PM


Subject: Re: how to work on multiple databases

On Sep 23, 2009, at 5:55 AM, go canal wrote:

Brian Candler

unread,
Oct 2, 2009, 3:29:41 AM10/2/09
to go canal, us...@couchdb.apache.org
On Tue, Sep 22, 2009 at 07:51:00PM -0700, go canal wrote:
> Are there APIs available for working on multiple databases ?

I contributed a change to CouchRest which lets you do

Foo.on(database).whatever

which directs your request to a database dynamically.

I haven't tested this in a while - I found CouchRest too complex internally
so I ended up knocking together my own API (couchtiny). I published it on
github.com/candlerb, although it's subject to change at my own whim :-)

> let's say a user wants to display a list of his documents in all projects,
> how do we support this ? Do I have to issue one query command for each
> database then aggregate the result ?

Yes. For me it's a feature, rather than a bug, that couchdb databases are
completely isolated from each other. Maybe you should consider lumping
everything into one database.

Regards,

Brian.

go canal

unread,
Oct 3, 2009, 1:34:44 AM10/3/09
to Brian Candler, us...@couchdb.apache.org
Yes. For me it's a feature, rather than a bug, that couchdb databases are
completely isolated from each other. Maybe you should consider lumping
everything into one database.


>> I can understand that couchdb DBs are completely isolated, I also agree that logically it is ok. But since there is no other layer we can use within a DB for modeling, I think operations on multiple databases are desired.

It does seem that putting something I need into one DB is the only way. Maybe it is acceptable since couchdb works incrementally, so performance won't be a problem even there is a large number of records because of combining multiple DBs into one ....
rgds,
canal

Sven Helmberger

unread,
Oct 3, 2009, 4:40:35 AM10/3/09
to us...@couchdb.apache.org
go canal schrieb:

>
> let's say a user wants to display a list of his documents in all projects, how do we support this ? Do I have to issue one query command for each database then aggregate the result ?
>

You could create an external indexer that collects results from all
project databases.

Regards,
Sven

Michael Miller

unread,
Oct 3, 2009, 10:59:58 AM10/3/09
to us...@couchdb.apache.org
I may have missed the beginning of this thread, apologies if these
were already discussed:

1) store the docs from different projects in the same db and use a
view to sort them via project
2) same but pack the project name and user into the _id field and use
the prebuilt _all_docs view to sort them via project/user
3) you can always combine db's using replication if you choose to
aggregate at a later point in time.

Happy to follow up offline if you have more questions.

-Mike

Reply all
Reply to author
Forward
0 new messages