2017-05-18 68 views
-1
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

,那麼請閱讀[詢問]如何在該機構中添加一些有意義的內容,而不是濫用標記,只是將標題複製到問題中。 – CodeCaster

+0

@CodeCaster嗯,我不知道還有什麼可說的:/這只是一個語法問題。 – Coder1000

回答

1

爲了讓您的votes場有意義的結構,使用對象而不是值對的數組(不能在貓鼬被嚴格定義):如果網站提到你的問題可以用更多的身體

votes: [{ 
    poll: {type: Schema.Types.ObjectId, ref: 'Poll'}, 
    count: {type: number} 
}] 
+0

你好!感謝你的回答 !你還想嘗試回答這個問題嗎? http://stackoverflow.com/questions/44052804/how-to-check-that-a-user-has-already-voted-on-a-poll – Coder1000