0
我正在使用MongoDB 2.6.7,我在MongoDB mode tree structure with array of ancestors之後創建了類別集合,但這個模型真的過於複雜,因此我想知道是否有人可以請最好的模型/架構設計,以便遵循以最好地實現我的分類收集需求,內容如下:類別集合的Mongodb模式建議
A. Build a tree with unlimited levels of categories and sub-categories
B. For any node in the tree I can easily know the list of this node ancestors
C. For any node in the tree I can easily know if it has any child nodes or not
D. I can only create sub-nodes (sub-categories) to those categories not referenced by any item in the inventory
E. I can move any sub-node in the tree along with its child-nodes to a different node, sod for example if i have:
- 1
--11
---111
---112
---113
-----1131
-----1132
-----1133
--12
---121
---122
---123
so I can move node 113 with its sub-children 1131, 1132, 1133 and place 113 under 123 so that it will look like this:
- 1
--11
---111
---112
--12
---121
---122
---123
-----113
--------1131
--------1132
--------1133
我當前類別集設計如下:
{ _id: "",
ancestors: [ ],
parent: ""
}
感謝您的幫助。
感謝您的幫助。因爲我可能會更新很多文件來更新祖先,所以在樹中重新分配特定節點時,子組會進行數組更新,或者在執行操作時鎖定整個集合,或者執行類似原子更新的操作以防止出現可能的問題如果另一個應用程序用戶在應用程序仍在更新重新分配的節點的祖先/孩子時嘗試更新樹? 在一個小問題上,我明白db.collection.update()在單個文檔上是原子的,所以我指的是在幾個文檔更新上處於原子狀態。謝謝 – MChan