couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jens Alfke <>
Subject Re: Best case for 1:many relation in CouchDB
Date Tue, 21 May 2013 16:16:35 GMT

On May 20, 2013, at 9:29 AM, Bernd Grolig <> wrote:

> But as soon as I want to have a reduce or grouping e.g. to "MainCat" or to
> "Division" I could not find a good solution to solve this.

If I understand correctly, the problem is that a transaction document contains the ID of its
category, and the category document contains the name of its main category, but there’s
no way for a map function to do the indirection and get a transaction’s main category. You’re
basically missing the functionality of a relational join.

> The only possibility I see is to put the Category names and Main Category
> Names and Division Names inside the document type of the transaction. But
> this would cause a lot of work for updates when the name of a category is
> changed.

If you created documents to represent the Main Categories and Divisions, then you could store
the readable name in the document and refer to them by their docIDs. That would eliminate
the overhead of renaming them. But it wouldn’t remove the overhead if you had to change
the MainCat of a category.

You might be able to do this with two levels of query: one to group/reduce transactions by
their category, and then a second one that groups categories by their MainCat. You’d still
need some application logic to combine the two queries to generate what you want.

(One thing I’ve found in CouchDB-type databases is that the queries aren’t going to do
as much of the work for you as in a SQL database. The downside can be more application code.
The upside, for me at least, is that application code is much easier for me to write and to
reason about than SQL.)

View raw message