Below is a Schema for my application. Under "meta" I have to fields that's called "upvotes" and "downvotes" and I want a field for the total amount of points (upvotes - downvotes). As for now I'm calculating this on the client side, but I also want to be able to sort by points (the image with most points first and descending).
Is there some way to auto 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 : ? // <- upvotes - downvotes
favs : Number,
uniqueIPs : [String],
tags : [String]
}
});