知道如何在 Mongoose Schema 中为 Tree 文档建模吗?
var TreeSchema = new Schema({
"Non-leafNode": {
"children": [
{
"type": "NodeElement"
}
]
},
"NodeElement": {
// one of them is required. not both.
"elem": {
"type": "LeafNode"
},
"elem2": {
"type": "Non-leafNode"
}
},
"LeafNode": {}
});
一个人怎么能做到这一点?整个树是一个文档(理想情况下)。
最佳答案
来自 https://groups.google.com/forum/#!topic/mongoose-orm/0yUVXNyprx8 :
By design, it might work. There's no tests for this. I have
Schema#add
in there for this purpose, to produce recursive references:
var Tasks = new Schema();
Tasks.add({
title : String
, subtasks : [Tasks]
});
所以你需要一步一步地构造递归。
关于node.js - 架构 : Mongoose modelling 中的递归元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33825773/