Model Tree Structures with Parent References
Overview
A tree-alike data model structure in mongo storing references to “parent”nodes in the child nodes.
Pattern
The Parent Reference pattern stores each tree node in a document; in addition to the tree, the document stores the id of the node’s parent.
Consider the following hierarchy of categories:
The following example models the tree using Parent
Reference, storing the reference to the parent category in the field parent: