couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Walter Werner <wer...@googlemail.com>
Subject Re: Modeling a tree in couchdb.
Date Mon, 02 Jan 2012 07:58:38 GMT
2011/12/30 Nils Breunese <N.Breunese@vpro.nl>:
> 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?
>
> Nils.
> ________________________________________
> Van: Jo-Erlend Schinstad [joerlend.schinstad@gmail.com]
> Verzonden: vrijdag 23 december 2011 11:47
> Aan: user@couchdb.apache.org
> 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
> ------------------------------------------------------------------------
>  VPRO   www.vpro.nl
> ------------------------------------------------------------------------

How about if every document get a parent attribute?

root document
id: 123
parent: undefined

child document
id: 768
parent: 123

child child document
id: 991
parent: 768


etc.

You need then a view with the parent as a key. With one request you
can get all his children (only 1 level) of a document. Then you
proceed with the children-documents and ask again whether they have
children. Maybe it will be a performance Issue, if your 'object' has
too many levels. The advantage is, that you don't have to think about
how the id's of your documents should look like.

Walter

Mime
View raw message