<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Sean Cribbs - Latest Comments in Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.disqus.com/</link><description></description><atom:link href="https://seancribbs.disqus.com/modeling_a_tree_in_a_document_database_sean_cribbs_digital_renaissance_man/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 04 Oct 2010 05:08:37 -0000</lastBuildDate><item><title>Re: Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.com/tech/2009/09/28/modeling-a-tree-in-a-document-database/#comment-83709039</link><description>&lt;p&gt;OrientDB is a document-graph dbms. The main difference with MongoDB and CouchDB is that all the relationships are stored as direct links. This speed up the load of entire trees and graphs of at least 10x.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Luca Garulli</dc:creator><pubDate>Mon, 04 Oct 2010 05:08:37 -0000</pubDate></item><item><title>Re: Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.com/tech/2009/09/28/modeling-a-tree-in-a-document-database/#comment-35730865</link><description>&lt;p&gt;You ought to also take a look at GT.M: its database is a naturally hierarchical schemaless architecture that makes the creation of trees very simple and natural.  The new M/Wire protocol - &lt;a href="http://www.mgateway.com/mwire.html" rel="nofollow noopener" target="_blank" title="http://www.mgateway.com/mwire.html"&gt;http://www.mgateway.com/mwi...&lt;/a&gt; - is now making GT.M a very accessible database. &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">robtweed</dc:creator><pubDate>Sun, 21 Feb 2010 13:22:21 -0000</pubDate></item><item><title>Re: Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.com/tech/2009/09/28/modeling-a-tree-in-a-document-database/#comment-32884588</link><description>&lt;p&gt;It seems like this is one of those things that is solved when you start treating your runtime as separate than your datastore, and is actually why I asked @jnunemaker about including an identity map in mongo_mapper a few months back. If you add an id to each node of the tree for the tree it is in, you can index the tree id, and quickly pull all nodes into the IM. When you walk the tree then, you'd only be assembling the graph in memory since you'd always get a hit in the IM. Or am I missing something?&lt;/p&gt;&lt;p&gt;This makes the strong assumptions that you're most frequently accessing the tree from the root node, and that you'd always want the full tree, so if you want the ability to quickly load any subtree this is non-optimal.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">adamaig</dc:creator><pubDate>Sat, 06 Feb 2010 21:12:11 -0000</pubDate></item><item><title>Re: Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.com/tech/2009/09/28/modeling-a-tree-in-a-document-database/#comment-31020210</link><description>&lt;p&gt;It looks like these sorts of structures are made simpler in couch 0.11:&lt;/p&gt;&lt;p&gt;&lt;a href="http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views#Linked_documents" rel="nofollow noopener" target="_blank" title="http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views#Linked_documents"&gt;http://wiki.apache.org/couc...&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">cemerick</dc:creator><pubDate>Sat, 23 Jan 2010 22:17:20 -0000</pubDate></item><item><title>Re: Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.com/tech/2009/09/28/modeling-a-tree-in-a-document-database/#comment-30652066</link><description>&lt;p&gt;@jnunemaker: can you give an example? Are the ancestors just a flat array or an array of arrays?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jamieorc</dc:creator><pubDate>Wed, 20 Jan 2010 23:17:20 -0000</pubDate></item><item><title>Re: Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.com/tech/2009/09/28/modeling-a-tree-in-a-document-database/#comment-30651654</link><description>&lt;p&gt;This is a good technique. It's simple and it also will scale (you can fragment the tree if it outgrows a single doc).&lt;/p&gt;&lt;p&gt;A common pattern in CouchDB is to cache the full path to the root on every node. Then a view lookup on the path will just work. The downside is you have to touch a lot of documents to do a high-level rename or move.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">J Chris A</dc:creator><pubDate>Wed, 20 Jan 2010 23:09:47 -0000</pubDate></item><item><title>Re: Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.com/tech/2009/09/28/modeling-a-tree-in-a-document-database/#comment-30105193</link><description>&lt;p&gt;This is how I modeled a graph in MongoDB : &lt;a href="http://bit.ly/6d6LKf" rel="nofollow noopener" target="_blank" title="http://bit.ly/6d6LKf"&gt;http://bit.ly/6d6LKf&lt;/a&gt; ... I rely on indices of the _id property only. However, to traverse one step in a graph, it requires two queries --- one to get the edges of the current vertex, and then one to get the vertex to traverse to.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Marko A. Rodriguez</dc:creator><pubDate>Sun, 17 Jan 2010 17:30:17 -0000</pubDate></item><item><title>Re: Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.com/tech/2009/09/28/modeling-a-tree-in-a-document-database/#comment-25990697</link><description>&lt;p&gt;Hogan, can you elaborate? You can only have one value per key in an JSON object, so I don't think I understand your solution.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Sean Cribbs</dc:creator><pubDate>Wed, 16 Dec 2009 19:24:10 -0000</pubDate></item><item><title>Re: Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.com/tech/2009/09/28/modeling-a-tree-in-a-document-database/#comment-25982120</link><description>&lt;p&gt;Make a heap.&lt;br&gt;&lt;br&gt;{ "id:a","id:b", "id:c", "id:d", "null", "null", "null" }&lt;br&gt;Working with heaps is easy.&lt;br&gt;-- For those that don't know, child-right is index*2, child-left is index*2+1, parent is floor(index/2)&lt;br&gt;(if it gets to big, make heap of heaps... say 255 nodes or something)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Hogan Long</dc:creator><pubDate>Wed, 16 Dec 2009 16:51:58 -0000</pubDate></item><item><title>Re: Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.com/tech/2009/09/28/modeling-a-tree-in-a-document-database/#comment-23634861</link><description>&lt;p&gt;Exactly, I was a bit too short with my comment.  We just build an index using:&lt;/p&gt;&lt;p&gt;for (node in doc.mpath) {&lt;br&gt;     emit( node, &amp;lt;something_to_aggregate&amp;gt;);&lt;br&gt;}&lt;/p&gt;&lt;p&gt;and then you've got a fully traversable index to query with start/endkey.  Augmented with a reduce function you can also then get summary statistics (e.g. total descendant count, tree level, etc).  We actually do a bunch of stuff in a single view by using complex keys:&lt;/p&gt;&lt;p&gt;emit( ["descendant_count", node], 1);&lt;br&gt;emit( ["daughters_at_depth", node_level], 1);&lt;br&gt;...&lt;/p&gt;&lt;p&gt;This is such a natural pattern that we should likely build it into couch as a default tree view&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mlmilleratmit</dc:creator><pubDate>Fri, 20 Nov 2009 13:41:58 -0000</pubDate></item><item><title>Re: Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.com/tech/2009/09/28/modeling-a-tree-in-a-document-database/#comment-23596768</link><description>&lt;p&gt;Yep, we are doing something similar. We store parent_id and parent_ids which is an array in mongo of all the ancestors up the tree. The benefit with mongo is you can index that and query on it to get all descendants as well.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jnunemaker</dc:creator><pubDate>Thu, 19 Nov 2009 22:50:49 -0000</pubDate></item><item><title>Re: Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.com/tech/2009/09/28/modeling-a-tree-in-a-document-database/#comment-21794726</link><description>&lt;p&gt;We've worked this out for customers, and the best solution I've seen in production is for a single document to represent a parent-child edge:&lt;/p&gt;&lt;p&gt;{&lt;br&gt;   "node" : "some_id",&lt;br&gt;   "parent": "parent_id",&lt;br&gt;   "mpath": [parent_id, that_nodes_parent,....,root]&lt;br&gt;}&lt;/p&gt;&lt;p&gt;The material path is the killer, because then a mapreduce view in couch will allow you to emit for each node in the material path to get aggregate counts for any sub-tree in the graph (assumes acyclic).&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mlmilleratmit</dc:creator><pubDate>Tue, 03 Nov 2009 17:00:52 -0000</pubDate></item><item><title>Re: Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.com/tech/2009/09/28/modeling-a-tree-in-a-document-database/#comment-19456557</link><description>&lt;p&gt;I'm just saying that document databases have different notions about how an index should be defined, and I was trying to reason about how to model this problem in the most idiomatic fashion for the datastore.  Most of these patterns wouldn't work in CouchDB unless you have a view defined, period. Well... they'd "work", but you'd be loading up a lot of documents just to find a few that you need.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Sean Cribbs</dc:creator><pubDate>Wed, 07 Oct 2009 17:07:50 -0000</pubDate></item><item><title>Re: Modeling a Tree in a Document Database - sean cribbs :: digital renaissance man</title><link>http://seancribbs.com/tech/2009/09/28/modeling-a-tree-in-a-document-database/#comment-19455845</link><description>&lt;p&gt;Since when is requiring an index a con?  Trying to do this with one hand tied behind your back?  :-D&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jim Van Fleet</dc:creator><pubDate>Wed, 07 Oct 2009 16:52:27 -0000</pubDate></item></channel></rss>