I have these two collections:
var wineSchema = new Schema({
name: { type: String }, //nombre del vino
code: { type:String},
type: {
type: String,
enum: ['Tinto','Rosado','Blanco']
},
winery: { type: String }, //Viñedo
grape_type: { type: String }, //tipo de uva
year: { type: Number }, // añada
alcohol: { type: Number }, //grados de alcohol
rates: [{ type: Schema.ObjectId, ref: "Puntuacion" }],
comentarios: [{ type: Schema.ObjectId, ref: "Comentario" }],
});
var puntuacion = new Schema({
usuario : { type: Schema.ObjectId, ref: "Usuario" },
usuName : {type: String},
vineName : { type: String},
puntuacion : { type: Number}
});
It is possible to make the average of all the punctuation scores.puntuation of each wine. The idea is to first make a populate pair that shows me all the wines with their respective scores and after all these make an average of punctuation.puntuacion with aggregate ..
I do not know if it is possible to do it .. Any ideas?