Monday, October 11, 2021

Model Tree Structures in Mongo DB

Hope this  document will  help  to model   hierarchical or nested data relationships with mongoDB .

MongoDB allows various ways to use tree data structures to model large hierarchical or nested data relationships.

Tree data model for a sample hierarchy of categories.
Model Tree Structures with Parent References
Presents a data model that organizes documents in a tree-like structure by storing references to "parent" nodes in "child" nodes.
Model Tree Structures with Child References
Presents a data model that organizes documents in a tree-like structure by storing references to "child" nodes in "parent" nodes.
Model Tree Structures with an Array of Ancestors
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.
Model Tree Structures with Materialized Paths
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 _id of the nodes ancestors or path as a string.
Model Tree Structures with Nested Sets
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.
 
Reference  Used :-   https://docs.mongodb.com/manual/applications/data-models-tree-structures/
 

Some interesting things to explore more

 Here  some  some  things  to  study  more ,     How Google Search works               https://developers.google.com/search/docs/fundamental...