var schema = new Schema({
firstName: {type: String, required: true},
lastName: {type: String, required: true},
password: {type: String, required: true},
email: {type: String, required: true, unique: true},
polls: [{type: Schema.Types.ObjectId, ref: 'Poll'}]
/*This is incorrect*/votes: [{{type: Schema.Types.ObjectId, ref: 'Poll'},{type: number}}]
});
答案 0 :(得分:1)
要为votes
字段提供有意义的结构,请使用对象数组而不是值对(在Mongoose中无法严格定义):
votes: [{
poll: {type: Schema.Types.ObjectId, ref: 'Poll'},
count: {type: number}
}]