我有以下场景:
用户可以登录到一个网站。用户可以添加/删除投票(一个包含两个选项的问题)。任何用户都可以选择其中之一来表达对投票的意见。
考虑以上情况,我有三个模型-
用户可以登录到一个网站。用户可以添加/删除投票(一个包含两个选项的问题)。任何用户都可以选择其中之一来表达对投票的意见。
考虑以上情况,我有三个模型-
Users
、Polls
和Options
。它们按依赖顺序如下:
选项架构
var optionSchema = new Schema({
optionName : {
type : String,
required : true,
},
optionCount : {
type : Number,
default : 0
}
});
投票架构
var pollSchema = new Schema({
question : {
type : String,
required : true
},
options : [optionSchema]
});
用户架构:父级架构
var usersSchema = new Schema({
username : {
type : String,
required : true
},
email : {
type : String,
required : true,
unique : true
},
password : String,
polls : [pollSchema]
});
我该如何在这些文档之间实现上述关系?什么是Mongoose population?它与子文档有什么不同?我应该选择子文档还是使用Mongoose population?