zoukankan      html  css  js  c++  java
  • MongoDB 树形模型

    Model Tree Structures with Parent References

    Overview

    A tree-alike data model structure in mongo storing references to “parent”nodes in the child nodes.

    Pattern

    The Parent Reference pattern stores each tree node in a document; in addition to the tree, the document stores the id of the node’s parent.

    Consider the following hierarchy of categories:

    image

    The following example models the tree using Parent

    Reference, storing the reference to the parent category in the field parent:

     

    Model Tree Structures with Child References

    Overview

    A tree-alike data model in mongo store references in the parent-nodes to children nodes.

    Pattern

    Consider the following hierarchy of categories:

    image

    The following example models the tree using Child References, storing the reference to the node’s children in the field children:

    Model Tree Structures with an Array of Ancestors

    Pattern

    Consider the following hierarchy of categories:

    image

     

    The following examples models the tree using Array of Ancestors.

    Model Tree Structures with Materialized Paths

    Pattern

    Consider the following hierarchy of categories:

    image

    The following examples models the tree using Materialized Path, storing the path in the field path. The path string uses the comma , as a delimiter:

    Model Tree Structures with Nested Sets

    Overview

    A tree-alike data model optimize discovering subtrees at the expense of tree mutability.

    Pattern

    The Nested Sets pattern identifies each node in the tree as stops in a round-trip traverse of tree. The application visits each node in the tree twice. First during the initial trip, and second during the return trip. The Nested Sets pattern stores each tree each tree node in a document. In addition to the tree node, document stores the id of node’s parent, the node’s initial stop in the left field, and its return stop in the right end.

    Consider the following hierarchy of categories:

    image

    The following example models the  tree using Nested Sets:

  • 相关阅读:
    MPI编程简述
    网购时代,写在消费者权益保护的新篇章大企业
    在哪里?
    H264 编解码器架构简单
    Unity+NGUI打造网络图片异步加载和本地缓存工具(一)
    分数减法
    JAVA设计模式(09):结构化-代理模式(Proxy)
    I2C驱动程序框架probe道路
    安卓表格布局android:collapseColumns,android:shrinkColumns和stretchColumn
    智课雅思词汇---七、cur是什么意思
  • 原文地址:https://www.cnblogs.com/hotbaby/p/4867911.html
Copyright © 2011-2022 走看看