couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nils Breunese <>
Subject RE: Modeling a tree in couchdb.
Date Thu, 29 Dec 2011 23:39:36 GMT
I love CouchDB, but I'm not sure I would use it for tree data. Have you looked into graph databases,
like Neo4j for instance?

Van: Jo-Erlend Schinstad []
Verzonden: vrijdag 23 december 2011 11:47
Onderwerp: Modeling a tree in couchdb.

For quite some time, I've been thinking about creating a Gtk TreeModel
that uses CouchDB as a backend. I've just started investigating it and
I've found some issues I don't know how to solve. I think this would be
useful for all kinds of trees, though, so it wouldn't be specific to
GTK. I hope someone can help.

The general idea is simple. The tree consists of nodes that can have
zero or one parent and zero or more children. So I thought each node
would be its own document with an ID like [model number, root node
number, child node number, child...], for instance,
{ "_id":[0, 0, 1,2] } would be the third child of the second child of
the first root node in the first model. This way, it would be easy to
get a single node or a range of nodes (including children) from a
specific model.

I have two problems with this; inserting, removing and moving nodes. If
I insert a node somewhere in the middle, all the documents after it
would need to get their IDs changed. I guess I could do this by looping
backwards from the end, incrementing the id in order to create a free
slot for the new node, (opposite for removals) but wouldn't this be
extremely slow for large collections? It should also be possible to
reorder rows, or just move something one step up or down. This would
ideally mean simply swapping the IDs of two documents, but I don't know
how to do this. I could give the first document a temporary value, then
change the value for the second to the old value of the first, and then
give the first the old value for the second. But the temporary value
might itself cause problems.

Any ideas or thoughts? I appreciate your insight.

Jo-Erlend Schinstad

View raw message