Schema 中的递归元素:Mongoose 建模
Recursive elements in Schema : Mongoose modelling
知道如何在 Mongoose Schema 中为树文档建模吗?
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]
});
所以需要一步步构造递归
知道如何在 Mongoose Schema 中为树文档建模吗?
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]
});
所以需要一步步构造递归