Q: Organize vote system with MongoDB I am making a vote system on my site. I have User model, which stores user information(name, password, settings, etc) and Poll model which represent user poll. What I should store and how in Poll model to create polls, where user can vote only once? I ended in next schema:
yesOption: {
    username: String,
    votes: [String] // Array of voted usernames 
}, 
noOption: {
    username: String,
    votes: [String],  
},
startDate: Date


A: //1. User
var UserSchema = new mongoose.Schema({
    username: {type: String, lowercase: true},
    email: {type: String, lowercase: true}
});

//2. Pool
var PoolSchema = new mongoose.Schema({
    rating: {type: Number, default: 0},
    votedNumber: {type: Number, default: 0}
});

//3. Voted
var VotedSchema = new mongoose.Schema({
    pool: {type: mongoose.Schema.Types.ObjectId, ref: 'Pool'}
    user: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
    rank: Number, //rank could be -1 and 1 (-1 is no and 1 is yes) or 0-5
    updatedAt: Date
});

If user voted already for this Pool you could update Voted object and Pool object. But usually user is allowed to vote once.
Also, to calculate rating for Pool you don't have to select all Voted documents from database. It is possible to recalculate it in 1 or 2 request to database:
if (('undefined' != typeof pool.votedNumber && pool.votedNumber) ||
    ('undefined' != typeof pool.rating && pool.rating)) {

    //Calculate new rating for a pool
    var numNewRating = ((pool.rating * pool.votedNumber) + newRank) / (pool.votedNumber + 1);
    place.votedNumber += 1;
    place.rating = parseFloat(numNewRating);

} else {
    //Pool is the first time ranked
    place.rating = parseFloat(newRank);
    place.votedNumber = 1;
}

