Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSQL schema for folder structure

Tags:

mongodb

nosql

I have documents that represent a folder structure. A folder can contain other folders (nested), theoretically unlimited levels deep but more realistically 3 or 4 levels for our application. I need to be able to retrieve a single item (a node) and perhaps embedding will make this task a bit difficult?

Any suggestions?

like image 911
Mark Nguyen Avatar asked Oct 28 '25 14:10

Mark Nguyen


1 Answers

The docs give a great summary of the more popular/common ways to store hierarchical data in mongodb.

Embedding documents - have significant drawbacks

  • Hard to search
  • Hard to get back partial results
  • Can get unwieldy if you need a huge tree. Further there is a limit on the size of documents in MongoDB – 16MB in v1.8 (limit may rise in future versions).

As you need to be able to retrieve single items - that is not likely to be the best option for your use case.

Array of ancestors or materialized path are likely to be much more suitable for what you've described - you could choose to use the full filepath for _id since that is unique and the path you would want to find data by more commonly.

like image 154
AD7six Avatar answered Oct 31 '25 12:10

AD7six