This modelling guarantee you atomicity of a document as mongodb write operationsare atomic at document level.

Indexes

Use indexes to improve performance for common queries. Build indexes on fields that appear often in queries and for all operations that return sorted results. MongoDB automatically creates a unique index on the _id field.

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

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 ReferencesPresents 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 AncestorsPresents 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 PathsPresents 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 SetsPresents 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.