【发布时间】:2021-05-07 20:57:13
【问题描述】:
我最近开始研究猫鼬,但我遇到了一个问题。 我要保存的数据类型如下图,
{
ObjectId('abcd')
allData,
parentId:null, // super parent level's parent id is always null
children:[
{
ObjectId('xyz')
allData,
parentId:ObjectId('abcd'),// id of parent
children:[
{
allData,
parentId:ObjectId('xyz'),// id of parent
children:[
{
... // nested levels can be N number of times
}
]
}
]
}
]
}
在上述数据中,只有一个模型在所有嵌套级别中递归使用。 那么猫鼬中有什么方法可以用来一次性保存上述类型的数据。即在一次调用中,我需要添加上述数据及其所有子级别。
【问题讨论】:
标签: node.js mongodb mongoose mongoose-schema