I have a product model, it has many fields. Some of them are intended for the front-end application, for example:
var GameSchema = new Schema({
likes: {
type: [{
type: Schema.ObjectId,
ref: 'User'
}]
},
likes_count: {
type: Number
}
});
I don't need a field likes_countin Db, but the controller returns only those fields that have a model, so I add the field likes_countto the db model
exports.some_method = function(req, res){
var game = req.game;
game.likes_count = game.likes.length
res.json(game);
}
Is there a way to add additional data to the db model when sending a request without using it in db?
Please note that the problem is not in the field itself likes_count, I have different models, but this point has additional data about the db model.
source
share