2

I want to store a filesystem tree into MongoDB within a Ruby application, so we are talking about json/bson representation of something like:

/
/foo
/foo/one
/foo/bar/two
/foo/bar/three
/four

my aim is to store it efficiently and to serve it via json to an Adobe Flex application which will display it in a Tree component.

which is the best solution in your opinion?
this document suggests some options. i'd like to go for something like the first pattern (keeping in mind the limit of 16Mb document size) with this format:

{"/" => [{"foo" => ["one", {"bar" => ["two", "three"]}]}, "four"]}

what do you think? is this a good format to store a hierarchical filesystem tree?

any suggestion is appreciated.

ALoR
  • 4,904
  • 2
  • 23
  • 25
  • That's a pretty standard representation of a tree, how do you plan on accessing it? Are you just pulling it out of MongoDB or will you be trying to look inside it while it is still in MongoDB? – mu is too short Apr 17 '11 at 22:11
  • possible duplicate of [MongoDB nested sets](http://stackoverflow.com/questions/1853735/mongodb-nested-sets) –  Apr 18 '11 at 04:50
  • @muistooshort: i will export it as it is to the flex application. maybe some basic search functionality will be implemented in the flex app, but i plan to handle it once the json object is converted to AS hash. – ALoR Apr 18 '11 at 06:45

1 Answers1

2

There are many ways to solve this problem, but here is the solutions that will be the easiest for Flex (not the server).

The example data you posted is a bit weird IMO. By default, the Flex tree component takes in an Object (of whatever types) and looks to see if there's a property called 'children' in it, if there is, it branches out from there.

So, if you wanted to display that directory structure in a tree component, you would send a JSON similar to this:

{name:'/', children:[{name:'foo', children:[{name:'one'},{name:'bar', children:[{name:'two'},{name:'three'}]}]},{name='four'}]}

Make sense?

J_A_X
  • 12,857
  • 1
  • 25
  • 31
  • thanks for the suggestion on the flex side. it will increase my json size. i've to check if the 16Mb limit is enough or not. maybe i will need some sort of "conversion" in the ruby layer, but i don't like it. waiting for others reply... let's see if someone has other advice. – ALoR Apr 18 '11 at 13:40
  • wait, what?! 16megs? Personally, I wouldn't use JSON since it's not very efficient. AMF is much better for larger datasets. Also, my example was just so that the Tree could display it easily. You could always do client side conversion, but client side conversion isn't very realistic if you've got 16 megs of data... What the hell are you implementing anyways? – J_A_X Apr 18 '11 at 13:50
  • it's a local application, so the data are exchanged locally, no web or remote interface, just local AIR application, so the transfer rate is not a problem. btw i don't think the 16Mb limit will ever be reached, that was the worst case scenario of someone wanting the entire HD displayed in the console, usually just few directory (recursively) in the home dir are gathered. AMF was not chosen because the flex app is not the only one requesting that data and we want a single api for all, json seemed the best choice. – ALoR Apr 18 '11 at 17:10
  • erm, you have an Air application that needs to communicate with a middleware solution to get the directory structure of the filesystem? You do know that Air can access the FS right? Anywho, you can always just use a json string to have `{'/':['foo':['one','bar':['one','three']], 'four']}`, but you'll need to parse it on the Flex side into a proper `HierarchicalData` structure for it to work in a Tree. – J_A_X Apr 18 '11 at 17:16
  • the filesystem i have to represent is not from the local machine... it is stored in the db by different "sensors" on different machines which collect their data and then the console is used to visualize them. – ALoR Apr 18 '11 at 20:13