Guest User

Untitled

a guest
Dec 18th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. {
  2. "_id" : ObjectId("5a377b895a2840568b1034d5"),
  3. "reportId" : 1234,
  4. "quantity" : 346
  5. },
  6. {
  7. "_id" : ObjectId("5a377b935a2840568b1034d6"),
  8. "reportId" : 1234,
  9. "users" : 96
  10. },
  11. {
  12. "_id" : ObjectId("5a377ba35a2840568b1034d7"),
  13. "reportId" : 2345,
  14. "quantity" : 566
  15. },
  16. {
  17. "_id" : ObjectId("5a377bac5a2840568b1034d8"),
  18. "reportId" : 2345,
  19. "users" : 66
  20. }
  21.  
  22. {'reportId': 1234, 'total':quantity * users}
  23. and so on
  24. where total in the multiplication of users and quantity
  25.  
  26. db.test1.aggregate([
  27. {'$group':
  28. { '_id':'$reportId',
  29. 'total':{'$multiply':['$users','$quantity']}
  30. }
  31. }])
  32.  
  33. assert: command failed: {
  34. "ok" : 0,
  35. "errmsg" : "The $multiply accumulator is a unary operator",
  36. "code" : 40237,
  37. "codeName" : "Location40237"
  38. } : aggregate failed
  39.  
  40. db.test1.aggregate([ {
  41. '$group':
  42. { '_id':'$reportId',
  43. 'document':{'$push':{'reportId':'$reportId',
  44. 'quantity':'$quantity','users':'$users'}}}},
  45. {'$unwind':'$document'}])
  46.  
  47. { "_id" : 2345, "document" : { "reportId" : 2345, "quantity" : 566 } }
  48. { "_id" : 2345, "document" : { "reportId" : 2345, "users" : 66 } }
  49. { "_id" : 1234, "document" : { "reportId" : 1234, "quantity" : 346 } }
  50. { "_id" : 1234, "document" : { "reportId" : 1234, "users" : 96 } }
Add Comment
Please, Sign In to add comment