MongoDB allows various ways to use tree data structures to model large hierarchical or nested data relationships.
- Presents a data model that organizes documents in a tree-like structure by storing references to "parent" nodes in "child" nodes.
- Presents a data model that organizes documents in a tree-like structure by storing references to "child" nodes in "parent" nodes.
- Presents a data model that organizes documents in a tree-like structure by storing references to "parent" nodes and an array that stores all ancestors.
- Presents a data model that organizes documents in a tree-like structure by storing full relationship paths between documents. In addition to the tree node, each document stores the
_idof the nodes ancestors or path as a string. - Presents a data model that organizes documents in a tree-like structure using the Nested Sets pattern. This optimizes discovering subtrees at the expense of tree mutability.