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?
The docs give a great summary of the more popular/common ways to store hierarchical data in mongodb.
Embedding documents – have significant drawbacks
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.