Answer the question
In order to leave comments, you need to log in
How to recalculate counters for a post?
I am developing a forum similar to Stackowerflow and want to consult with you on the best way to store counters: the number of ratings, views and the choice of the best answer.
I am using Nodejs/MongoDB. Right now I have two collections:
Posts :
[{
_id: ObjectId(1),
title: 'Untitled',
content: 'empty'
}]
[{
_post: ObjectId(1),
_user: ObjectId(...),
vote: 1,
}, {
_post: ObjectId(1),
_user: ObjectId(...),
vote: 1,
}]
Votes.create({_post: ObjectId(1), vote: 1}).exec(cb);
[{
_id: ObjectId(1),
title: 'Untitled',
content: 'empty',
votes: 2
}]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question