Below is a diagram for my application. In the meta section, I have fields called upvotes and downvotes, and I want a field for the total number of points (upvotes - downvotes). At the moment I am counting this on the client side, but I also want to be able to sort by points (the image with the most points at the beginning and the descent).
Is there a way to automatically calculate a field in Mongoose, and if so, how is it done?
var ImageSchema = new Schema({ name : String, size : Number, title : String, body : String, buf : Buffer, date: { type: Date, default: Date.now }, comments : [CommentSchema], meta : { upvotes : Number, downvotes : Number, points : ?
source share