Help with aggregation count, average, sort and pagination

  1. Calculate - Total Ratings Count, Average Ratings.
  2. List - All Comments and ratings including sorting (on basis of rating) & pagination.

I need help with this. This is how my ratings schema looks.
Need the aggregation logic for this.

Hello @Atul_tiwari,

Welcome again to MongoDB Developer Forum,

You could build aggregation pipeline (aggregate()) using below pipeline stages,

  • You can use $group stage to group by movie_id
  • get average rating by $avg operator
  • You can use $sort for sorting by rating

  • for pagination you can use $skip and $limit

  • List - All Comments” This is little unclear, how you want list of all comments

For more better answer you need to describe your expected result.