Schema for User Ratings - Key/Value DB

前端 未结 4 984
暖寄归人
暖寄归人 2021-02-02 18:15

We\'re using MongoDB and I\'m figuring out a schema for storing Ratings.

  • Ratings will have values of 1-5.
  • I want to store other values such as from
4条回答
  •  一个人的身影
    2021-02-02 18:32

    The Below code can be used to get the average rating for each users.

    db.ratings.aggregate([
     {
     $match:{ rated: '$user' },
     },
     {
     $order: {
      _id: "$rated",
      average: { $avg: "$rating" }
     }
     ])
    

提交回复
热议问题