Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //total
  2. db.orders.aggregate(
  3.     {
  4.         $group: {
  5.             _id: null,
  6.             total: {
  7.                 $sum: '$Freight'
  8.             }
  9.         }
  10.     }
  11. );
  12.  
  13. //France
  14. db.orders.aggregate(
  15.     {
  16.         $match: {
  17.             ShipCountry: 'France'
  18.         }
  19.     },
  20.     {
  21.         $project: {
  22.             Freight: 1
  23.         }
  24.     },
  25.     {
  26.         $group: {
  27.             _id: null,
  28.             total: {
  29.                 $sum: '$Freight',
  30.             },
  31.             totalOrders: {
  32.                 $sum: 1
  33.             }
  34.         }
  35.     }
  36. )
  37.  
  38.  
  39.  
  40. // total frieght by country
  41. db.orders.aggregate(
  42.     {
  43.         $project: {
  44.             country: '$ShipCountry',
  45.             amount: '$Freight'
  46.         }
  47.     },
  48.     {
  49.         $group: {
  50.             _id: '$country',
  51.             total: {
  52.                 $sum: '$amount'
  53.             },
  54.             totalOrders: {
  55.                 $sum: 1
  56.             }
  57.         }
  58.     }
  59. )
  60.  
  61.  
  62.  
  63.  
  64.  
  65. db.orders.aggregate(
  66.     {
  67.         $group: {
  68.             _id: null,
  69.             total: {
  70.                 $sum: '$Freight'
  71.             }
  72.         }
  73.     }
  74. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement