mercredi 3 février 2021

How to set value from aggregation of another collection in Mongoose and also in MongoDB

I'm new to mongoose and mongodb. I got problem when on doing my project. So i have to assign rating field in courses collection a value which is the average of rating field in reviews collection. This is the illustration:

Course({
  _id: "1",
  name: "math",
  rating: (the average of rating group by course id);
})

Rating({
  _id: "1",
  rating: 5,
  course_id: "1",
  user_id: "1"
}, {
  id: "2",
  rating: 4,
  course_id: "1",
  user_id: "2"
})

Aucun commentaire:

Enregistrer un commentaire