Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Trees in MongoDB
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Voltron  
View profile  
 More options Oct 14 2009, 11:32 am
From: Voltron <nhy...@googlemail.com>
Date: Wed, 14 Oct 2009 08:32:21 -0700 (PDT)
Local: Wed, Oct 14 2009 11:32 am
Subject: Trees in MongoDB
First of, thanks to Sean Cribs, he posed the question so well in his
blog entry here(http://seancribbs.com/tech/2009/09/28/modeling-a-tree-
in-a-document-database/)

I am facing the problem of creating trees in MongoDB too at the
moment, based on the methods detailed by Sean, what would be the
method to choose for MongoDb and where would one place the indexes?
Are there other ways?

Sean did not get many answers, so I decided to ask the MongoDB devs
and users directly.

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mathias Stearn  
View profile  
 More options Oct 14 2009, 12:11 pm
From: Mathias Stearn <math...@10gen.com>
Date: Wed, 14 Oct 2009 12:11:45 -0400
Local: Wed, Oct 14 2009 12:11 pm
Subject: Re: Trees in MongoDB

One method that he didn't cover is storing fully-qualified paths. This gives
you efficient subtree querying and each node knows all of it's parents. I
haven't benchmarked this, but I think it will work well for low-depth trees.
I'll use ':' as the path separator so that it can be used unescaped in a
regex.
first insert documents like this and add an index on "path" (or just put it
in the _id field which is automatically indexed) :
{path: "a", data: STUFF}
{path: "a:b"}
{path: "a:c"}
{path: "a:c:d"}
{path: "e"}

You could then fetch the subtree rooted at "a" using find({path: /^a/}).
Mongo uses an index for all prefix queries so that will be very efficient.

If you are at node "a:c:d" and want the parent objects you can get that with
find({path: {$in: {'a', 'a:d'}}}).

I haven't benchmarked this against the other methods, but for subtree
searches this should be pretty good. Also, it should ensure a good locality
to your subtrees if you use the path as the shard-key.

If you have deep trees then either the parent_id or the child list method
would work well but will require many round trips (one per level) to fetch
whole sub-trees. Just make sure you index the children and parent_id fields.
You could always start by using all three methods and then see what works
best for you.

-Mathias


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Voltron  
View profile  
 More options Oct 15 2009, 2:27 pm
From: Voltron <nhy...@googlemail.com>
Date: Thu, 15 Oct 2009 11:27:20 -0700 (PDT)
Local: Thurs, Oct 15 2009 2:27 pm
Subject: Re: Trees in MongoDB
Thanks Mathias!

On Oct 14, 6:11 pm, Mathias Stearn <math...@10gen.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »