Guest User

Untitled

a guest
Apr 24th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. { "_id" : { "borough" : "Manhattan", "cuisine" : "Tex-Mex" }, "RestaruntCount" : 53 }
  2. { "_id" : { "borough" : "Manhattan", "cuisine" : "Bakery" }, "RestaruntCount" : 221 }
  3. { "_id" : { "borough" : "Manhattan", "cuisine" : "Soups & Sandwiches" }, "RestaruntCount" : 44 }
  4. { "_id" : { "borough" : "Manhattan", "cuisine" : "Vietnamese/Cambodian/Malaysia" }, "RestaruntCount" : 38 }
  5. { "_id" : { "borough" : "Manhattan", "cuisine" : "Filipino" }, "RestaruntCount" : 5 }
  6. { "_id" : { "borough" : "Manhattan", "cuisine" : "Egyptian" }, "RestaruntCount" : 5 }
  7. { "_id" : { "borough" : "Manhattan", "cuisine" : "Nuts/Confectionary" }, "RestaruntCount" : 4 }
  8.  
  9. db.restaurants.aggregate( [ { $match: { "borough": "Manhattan" } }, { $group: {_id: {borough:"$borough", cuisine: "$cuisine"}, count : { $sum : 1} } }, {$sort: {count:1,_id:1}} ] );
  10.  
  11. db.restaurants.aggregate([
  12. {
  13. $match: { "_id.borough": "Manhattan" }
  14. },
  15. {
  16. $sort: { RestaruntCount: 1 }
  17. },
  18. {
  19. $group: {
  20. _id: null,
  21. first: { $first: "$$ROOT" },
  22. last: { $last: "$$ROOT" }
  23. }
  24. }
  25. ])
Add Comment
Please, Sign In to add comment