Simple voting system with MongoDB

quick question. I have a list of artwork in mongodb and I want users to be able to raise or lower the voice for the original.

My first way would be in the art collection to have two lines called upvote and downvote that would have numbers like upvote: 360 downvote: 102;

then I will need to order this by doing the amount of upvote-downvote, this will show the total number of similar articles.

My question at mongoDB is the best way to do this, or I'm better off with one “vote”, and then just order it with that vote.

thank

+5
source share
1 answer

, , , . , , .

"" , , , :

votes: [ 
        { voter:"name or ID or IP address or some other unique identifier for the person who voted",
          vote:-1 },
        { voter:"someone else",
          vote:1 },
        { voter:"and someone entirely different",
          vote:-1 }
    ]

vote.voter, , .

"-1" downvote "1" upvote, $sum ( , ).

+7

All Articles