【发布时间】:2016-12-17 04:59:41
【问题描述】:
我有以下情景:
用户可以登录网站。用户可以添加/删除投票(一个有两个选项的问题)。任何用户都可以通过选择任何选项对投票发表意见。
考虑到上述情况,我有三个模型 - 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 种群。
【问题讨论】:
-
如果您有任何问题,请继续 - 请在下方回答。如果对您有帮助,我将不胜感激;)
标签: node.js mongodb mongoose crud