模式中的递归元素:猫鼬建模 [英] Recursive elements in Schema : Mongoose modelling
本文介绍了模式中的递归元素:猫鼬建模的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么想法如何在猫鼬模式中对Tree文档进行建模?
Any idea how to model a Tree document in 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": {}
});
一个人该如何建模?整个树是一个文档(理想情况下).
How could one model this? The entire Tree is one document (ideally).
推荐答案
来自 https://groups.google.com/forum/#!topic/mongoose-orm/0yUVXNyprx8 :
通过设计,它可能会起作用.没有为此的测试.为此,我有
Schema#add
来产生递归引用:
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]
});
因此,您需要逐步构建递归.
So you need to construct the recursion step by step.
这篇关于模式中的递归元素:猫鼬建模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文