我在node js上使用mongoose,并且我有一个Page集合,比如
{
"_id" : ObjectId("5b3cf0e7ee00450156711a47"),
"language" : "en",
"published" : true,
"content" : [
{
"title" : "my title 1",
"subTitle" : "subtitle 1",
"items" : [
{
"title" : "my item title 1",
"subTitle" : "item subtitle 1",
},
{
"title" : "my item title 2",
"subTitle" : "item subtitle 2",
}
]
},
{
"title" : "my title 2",
"subTitle" : "subtitle 2",
}
],
"createdAt" : ISODate("2018-07-04T16:08:07.057Z"),
"__v" : 0
}"content“数组包括许多对象,其中一些对象包括也包括许多对象"items”数组。(嵌套在2层深)
我想知道引用content对象是否比嵌套它们更好,因为它们也有嵌套的文档(在items中),所以这是2层深的嵌套。我必须使用page.content.id(listId).items.id(id)来查找它们,并使用page.content.id(listId).items.id(id)[key] = value; page.save();来更新它们。
考虑到最多应该有3个“项目”和5个“内容”,你认为最好的解决方案是什么,更新嵌套在2级深度文档或具有引用/集合的内容?
我还计划做一个版本化,这将影响这个决定,因为更新可以/将创建文档的新版本。
发布于 2018-07-05 20:21:01
我更喜欢在这里收集参考资料。
页面架构
{
"language" : String,
"published" : Boolean,
"content" : [
{type: mongoose.Schema.Types.ObjectId, ref: 'content'}
],
"createdAt" : Date,
}内容架构
{
"title" : String,
"subTitle" : String,
"items": [{type: mongoose.Schema.Types.ObjectId, ref: 'items'}]
}项目架构
{
"title" :String,
"subTitle" : String,
}https://stackoverflow.com/questions/51189644
复制相似问题