Quantcast
Channel: MongoDB | Blog
Viewing all articles
Browse latest Browse all 2423

Building with Patterns: The Tree Pattern

$
0
0
Many of the schema design patterns we've covered so far have stressed that saving time on JOIN operations is a benefit. Data that's accessed together should be stored together and some data duplication is okay. A schema design pattern like [Extended Reference](https://www.mongodb.com/blog/post/building-with-patterns-the-extended-reference-pattern) is a good example. However, what if the data to be joined is hierarchical? For example, you would like to identify the reporting chain from an employee to the CEO? MongoDB provides the [$graphLookup](https://docs.mongodb.com/manual/reference/operator/aggregation/graphLookup/) operator to navigate the data as graphs, and that could be one solution. However, if you need to do a lot of queries of this hierarchical data structure, you may want to apply the same rule of storing together data that is accessed together. This is where we can use the Tree Pattern.

Viewing all articles
Browse latest Browse all 2423

Trending Articles