Node.js 模式中的递归元素:Mongoose建模
知道如何在Mongoose模式中建模树文档吗Node.js 模式中的递归元素:Mongoose建模,node.js,mongodb,mongoose,schema,Node.js,Mongodb,Mongoose,Schema,知道如何在Mongoose模式中建模树文档吗 var TreeSchema = new Schema({ "Non-leafNode": { "children": [ { "type": "NodeElement" } ] }, "NodeElement": { // one of them is required. not both.
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": {}
});
一个人怎么能这样做呢?整个树是一个文档(理想情况下)。来自:
根据设计,它可能会起作用。这个没有测试。为此,我在其中添加了Schema
,以生成递归引用:
因此,您需要一步一步地构造递归。您将如何填充它?如果您想在一个Mongo文档中获取所有Tasks的所有子代的所有信息,那么它已经被填充了
var Tasks = new Schema();
Tasks.add({
title : String
, subtasks : [Tasks]
});