nickzuck_007

feedback option stats

Mar 15th, 2019
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.89 KB | None | 0 0
  1. db.feedbacks.aggregate([
  2.     {$match : {
  3.                 "collection": "tests",
  4.                 "docId": {$in : [ObjectId("56c6dc8a995a2d6dc85f45eb") , ObjectId("5abcaf934e04790c26cad289"), ObjectId("56c6de2b995a2d6dc85f4828")]}
  5.                 }
  6.     },
  7.     {$unwind : "$mo"},
  8.     {
  9.         $lookup : {
  10.             from : "feedback_options",
  11.             localField: "mo",
  12.             foreignField: "_id",
  13.             as : "option_details"
  14.         }
  15.     },
  16.     {$project : {
  17.         "mo": 1,
  18.         "option_details": {$arrayElemAt: ["$option_details", 0]},
  19.         "rating": 1
  20.         }
  21.     },
  22.     {$match : {"rating": {$in : [1, 2, 3, 4,5]}}},
  23.     {$group :
  24.             {
  25.                 _id: "$mo",
  26.                count : {$sum : 1},
  27.                optionText : {$first : "$option_details.text"},
  28.                ratings : {$addToSet : "$rating"}
  29.             }
  30.     }
  31. ])
Advertisement
Add Comment
Please, Sign In to add comment