Model Tree Structures
MongoDB allows various ways to use tree data structures to model largehierarchical or nested data relationships.
- Model Tree Structures with Parent References
- Presents a data model that organizes documents in a tree-likestructure by storing referencesto “parent” nodes in “child” nodes.
- Model Tree Structures with Child References
- Presents a data model that organizes documents in a tree-likestructure by storing referencesto “child” nodes in “parent” nodes.
- Model Tree Structures with an Array of Ancestors
- Presents a data model that organizes documents in a tree-likestructure by storing referencesto “parent” nodes and an array that stores all ancestors.
- Model Tree Structures with Materialized Paths
- Presents a data model that organizes documents in a tree-likestructure by storing full relationship paths between documents. Inaddition to the tree node, each document stores the
_id
of thenodes ancestors or path as a string. - Model Tree Structures with Nested Sets
- Presents a data model that organizes documents in a tree-likestructure using the Nested Sets pattern. This optimizesdiscovering subtrees at the expense of tree mutability.