I'm trying to get the average of a field called Score that is inside an array of objects.
This is the sentence with which I tried to get it
db.classroom.aggregate([{$group : { _id : "$_id", puntaje : { $avg : "${userScore.score}" }}}])
The collection called Classroom is the following
{
"_id" : ObjectId("56a0b43541c1375cd4e90b85"),
"name" : "Desarrollo de Software",
"comment" : "Salon destinado al Desarollo de Software",
"code" : [
{
"code" : "ABCDEF123456",
"user" : [
DBRef("user", 201309)
]
}
],
"post" : [
{
"post" : "Me gusta el salon :)",
"date" : ISODate("-292275055-05-16T16:47:03.192Z"),
"user" : DBRef("user", 201309)
}
],
"userScore" : [
{
"score" : 4.5,
"user" : DBRef("user", 201309)
}
]
}
Why the avg is always null ?