0

I am challenged with persisting a structure that is inherently tree-like:

  • a drawing can have multiple layers
  • a layer can have multiple lines
  • a line can have multiple points

My current implementation is with MongoDB, points as an Array attribute of lines and the rest handled with has_many associations.

I read http://docs.mongodb.org/manual/tutorial/model-tree-structures where a better approach is explained, and I'm probably going to upgrade to that, if it is the best avenue.

The biggest impact on DB is when I want to change a drawing, keeping the previous version: I'm deep copying the entire tree, to prevent side effects. I know, I could go with of copy-on-write, but I still have to figure it out.

I want to know if there is any better approach/DB I could use for managing tree structures.

In my opinion:

  • I cannot use RDBMS because of the number of joins involved (monstrous)
  • Neo4J is overkill
  • having everything inside a single Mongo document is hard to manage and could potentially go over the 16MB max size limit

What's your experience with trees?

Community
  • 1
  • 1
aledalgrande
  • 5,167
  • 3
  • 37
  • 65
  • I would have said "keep the whole drawing in one document because it's unlikely that you will ever need to data-mine it" until I read about the 16MB limit. – Philipp Jan 22 '14 at 21:07
  • In an RDBMS the number of joins is not monstrous at all; you only have three tables! It is quite normal to have SQL queries which join 10 or more tables and complete in milliseconds. Your setup sounds far simpler than most Databases I work with. Not that I'm saying use an RDBMS, just that that's not a valid reason not to. – simon at rcl Jan 23 '14 at 10:32
  • It's hard to give you a great answer here without knowing more, but here are some thoughts: - Is there a particular reason you want to store this in a database at all? I don't do a lot of graphics programming but I feel like most things like the vector image you're describing are stored in flat files (like svg). If you went this route, you could still use mongodb with GridFS to store them in a scalable way. – 3rf Jan 23 '14 at 16:46
  • @simonatrcl that's true. I was too hasty in considering that. – aledalgrande Jan 23 '14 at 18:08
  • @3rf I want to keep them in DB because I will change parts of them programmatically, so I can reference just parts of them, instead of loading the an entire file that has then to be parsed. – aledalgrande Jan 23 '14 at 18:09

0 Answers0