MongoDB Documentation, Release 3.0.4 • You can query to retrieve the whole tree, sorting by the field path : db.categories.find().sort( { path: 1 } ) db.categories.find( { path: /,Programming,/ } ) db.categories.find( { path: /^,Books,/ } ) db.categories.createIndex( { path: 1 } ) • You can use regular expressions on the path field to find the descendants of Programming : • You can also retrieve the descendants of Books where the Books is also at the topmost level of the hierarchy: • To create an index on the field path use the following invocation: – For queries from the root Books sub-tree (e.g. http://docs.mongodb.org/manual/^,Books,/ or http://docs.mongodb.org/manual/^,Books,Programming,/ ), an index on the path field improves the query performance significantly. – For queries of sub-trees where the path from the root is not provided in the query (e.g. http://docs.mongodb.org/manual/,Databases,/ ), or similar queries of sub-trees, where the node might be in the middle of the indexed string, the query must inspect the entire index. This index may improve performance depending on the query: For these queries an index may provide some performance improvement if the index is significantly smaller than the entire collection. Chapter 4. Data Models 162