incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Metin Akat <>
Subject Tree structure: how to calculate branch node sum, using results from a view that calculates leaf node sums.
Date Thu, 03 Sep 2009 12:35:29 GMT
I am writing an accounting application.
Generally, so far my design is as follows:

1. Account document.

2. Transaction document. It has kind of the usual structure...
"debit", "credit", "qty", "value" etc.
Here "debit" and "credit" are two account UUIDs

I have a view with a reduce, that emits all the transactions for each
account and calculates the account balance.
Something quite similar to what is described here:

The accounts are a tree structure. Every account can have child
accounts. And transactions are only executed against
accounts that have no children (leaf nodes).
So far I have no problems in calculating the balance of the leaf nodes.

Every node in the tree has a property called "lineage" that is a list
with its "path" in the tree.

So what I'm trying to do now is to calculate the balance of the branch
nodes across the tree.

One way is to do it client side (fetch all the leafs (view collation)
that belong to some branch and calculate the balance in my
This won't be a great problem, because I don't really believe that
I'll have more than several hundred leafs altogether.
Though I'm still interested to find out if there is some "cool" way to
do it with couchdb.

View raw message