content_image/822275.jpg
db.categories.find( { children: "MongoDB" } ) 

The Child References pattern provides a suitable solution to tree storage as long as no operations on subtrees are necessary. This pattern may also provide a suitable solution for storing graphs where a node may have multiple parents. 

## Model Tree Structures with an Array of Ancestors 

## Overview 

Data in MongoDB has a flexible schema . Collections do not enforce document structure. Decisions that affect how you model data can affect application performance and database capacity. See Data Modeling Concepts (page 145) for a full high level overview of data modeling in MongoDB. 

This document describes a data model that describes a tree-like structure in MongoDB documents using references (page 147) to parent nodes and an array that stores all ancestors. 

## Pattern 

The Array of Ancestors pattern stores each tree node in a document; in addition to the tree node, document stores in an array the id(s) of the node’s ancestors or path. 

Consider the following hierarchy of categories: 

<img src='content_image/822275.jpg'>

