I have a collection named "Restaurants" which looks like this:
{
"_id" : ObjectId("51236fbc3004f02f87c62e8e"),
"name" : "Some very fancy name"
reviews: [
{"id" : 1,
"text" : "saffas"
"rating" : 3,
}
{"id" : 2,
"text" : "fsafasfas"
"rating" : 4,
}
]
}
I would like to get an average rating of all of the reviews of the restaurant. How can I do this (I use Java)?
Run the following aggregation pipeline to get the average rating of a restaurant:
Mongo shell
This can be translated to Java as:
Java test implementation