// NMEC: 104063 // 1. Liste todos os documentos da coleção. db.restaurants.find() // { "_id" : ObjectId("6712e9eb8c188b676f5c4aef"), "address" : { "building" : "351", "coord" : [ -73.98513559999999, 40.7676919 ], "rua" : "West 57 Street", "zipcode" : "10019" }, "localidade" : "Manhattan", "gastronomia" : "Irish", "grades" : [ { "date" : ISODate("2014-09-06T00:00:00Z"), "grade" : "A", "score" : 2 }, { "date" : ISODate("2013-07-22T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2012-07-31T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2011-12-29T00:00:00Z"), "grade" : "A", "score" : 12 } ], "nome" : "Dj Reynolds Pub And Restaurant", "restaurant_id" : "30191841" } { "_id" : ObjectId("6712e9eb8c188b676f5c4af0"), "address" : { "building" : "2780", "coord" : [ -73.98241999999999, 40.579505 ], "rua" : "Stillwell Avenue", "zipcode" : "11224" }, "localidade" : "Brooklyn", "gastronomia" : "American", "grades" : [ { "date" : ISODate("2014-06-10T00:00:00Z"), "grade" : "A", "score" : 5 }, { "date" : ISODate("2013-06-05T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2012-04-13T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2011-10-12T00:00:00Z"), "grade" : "A", "score" : 12 } ], "nome" : "Riviera Caterer", "restaurant_id" : "40356018" } { "_id" : ObjectId("6712e9eb8c188b676f5c4af1"), "address" : { "building" : "469", "coord" : [ -73.961704, 40.662942 ], "rua" : "Flatbush Avenue", "zipcode" : "11225" }, "localidade" : "Brooklyn", "gastronomia" : "Hamburgers", "grades" : [ { "date" : ISODate("2014-12-30T00:00:00Z"), "grade" : "A", "score" : 8 }, { "date" : ISODate("2014-07-01T00:00:00Z"), "grade" : "B", "score" : 23 }, { "date" : ISODate("2013-04-30T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2012-05-08T00:00:00Z"), "grade" : "A", "score" : 12 } ], "nome" : "Wendy'S", "restaurant_id" : "30112340" } { "_id" : ObjectId("6712e9eb8c188b676f5c4af2"), "address" : { "building" : "97-22", "coord" : [ -73.8601152, 40.7311739 ], "rua" : "63 Road", "zipcode" : "11374" }, "localidade" : "Queens", "gastronomia" : "Jewish/Kosher", "grades" : [ { "date" : ISODate("2014-11-24T00:00:00Z"), "grade" : "Z", "score" : 20 }, { "date" : ISODate("2013-01-17T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2012-08-02T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2011-12-15T00:00:00Z"), "grade" : "B", "score" : 25 } ], "nome" : "Tov Kosher Kitchen", "restaurant_id" : "40356068" } { "_id" : ObjectId("6712e9eb8c188b676f5c4af3"), "address" : { "building" : "2206", "coord" : [ -74.1377286, 40.6119572 ], "rua" : "Victory Boulevard", "zipcode" : "10314" }, "localidade" : "Staten Island", "gastronomia" : "Jewish/Kosher", "grades" : [ { "date" : ISODate("2014-10-06T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2014-05-20T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2013-04-04T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2012-01-24T00:00:00Z"), "grade" : "A", "score" : 9 } ], "nome" : "Kosher Island", "restaurant_id" : "40356442" } { "_id" : ObjectId("6712e9eb8c188b676f5c4af4"), "address" : { "building" : "8825", "coord" : [ -73.8803827, 40.7643124 ], "rua" : "Astoria Boulevard", "zipcode" : "11369" }, "localidade" : "Queens", "gastronomia" : "American", "grades" : [ { "date" : ISODate("2014-11-15T00:00:00Z"), "grade" : "Z", "score" : 38 }, { "date" : ISODate("2014-05-02T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2013-03-02T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2012-02-10T00:00:00Z"), "grade" : "A", "score" : 13 } ], "nome" : "Brunos On The Boulevard", "restaurant_id" : "40356151" } (...) // 2. Apresente os campos restaurant_id, nome, localidade e gastronomia para todos os documentos da coleção. db.restaurants.find({}, {restaurant_id: 1, nome: 1, localidade: 1, gastronomia: 1}) { "_id" : ObjectId("6712e9eb8c188b676f5c4aef"), "localidade" : "Manhattan", "gastronomia" : "Irish", "nome" : "Dj Reynolds Pub And Restaurant", "restaurant_id" : "30191841" } { "_id" : ObjectId("6712e9eb8c188b676f5c4af0"), "localidade" : "Brooklyn", "gastronomia" : "American", "nome" : "Riviera Caterer", "restaurant_id" : "40356018" } { "_id" : ObjectId("6712e9eb8c188b676f5c4af1"), "localidade" : "Brooklyn", "gastronomia" : "Hamburgers", "nome" : "Wendy'S", "restaurant_id" : "30112340" } { "_id" : ObjectId("6712e9eb8c188b676f5c4af2"), "localidade" : "Queens", "gastronomia" : "Jewish/Kosher", "nome" : "Tov Kosher Kitchen", "restaurant_id" : "40356068" } { "_id" : ObjectId("6712e9eb8c188b676f5c4af3"), "localidade" : "Staten Island", "gastronomia" : "Jewish/Kosher", "nome" : "Kosher Island", "restaurant_id" : "40356442" } { "_id" : ObjectId("6712e9eb8c188b676f5c4af4"), "localidade" : "Queens", "gastronomia" : "American", "nome" : "Brunos On The Boulevard", "restaurant_id" : "40356151" } { "_id" : ObjectId("6712e9eb8c188b676f5c4af5"), "localidade" : "Brooklyn", "gastronomia" : "Delicatessen", "nome" : "Wilken'S Fine Food", "restaurant_id" : "40356483" } (...) // 3. Apresente os campos restaurant_id, nome, localidade e código postal (zipcode), mas exclua o campo _id de todos os documentos da coleção. db.restaurants.find({}, {restaurant_id: 1, nome: 1, localidade: 1, "address.zipcode": 1, _id: 0 }) { "address" : { "zipcode" : "10019" }, "localidade" : "Manhattan", "nome" : "Dj Reynolds Pub And Restaurant", "restaurant_id" : "30191841" } { "address" : { "zipcode" : "11224" }, "localidade" : "Brooklyn", "nome" : "Riviera Caterer", "restaurant_id" : "40356018" } { "address" : { "zipcode" : "11225" }, "localidade" : "Brooklyn", "nome" : "Wendy'S", "restaurant_id" : "30112340" } { "address" : { "zipcode" : "11374" }, "localidade" : "Queens", "nome" : "Tov Kosher Kitchen", "restaurant_id" : "40356068" } { "address" : { "zipcode" : "10314" }, "localidade" : "Staten Island", "nome" : "Kosher Island", "restaurant_id" : "40356442" } { "address" : { "zipcode" : "11369" }, "localidade" : "Queens", "nome" : "Brunos On The Boulevard", "restaurant_id" : "40356151" } { "address" : { "zipcode" : "11234" }, "localidade" : "Brooklyn", "nome" : "Wilken'S Fine Food", "restaurant_id" : "40356483" } { "address" : { "zipcode" : "10460" }, "localidade" : "Bronx", "nome" : "Wild Asia", "restaurant_id" : "40357217" } (...) // 4. Indique o total de restaurantes localizados no Bronx. db.restaurants.count({"localidade": "Bronx"}) 309 // 5. Apresente os primeiros 15 restaurantes localizados no Bronx, ordenados por ordem crescente de nome. db.restaurants.find({"localidade": "Bronx"}).sort({"nome": 1}).limit(15) { "_id" : ObjectId("6712e9eb8c188b676f5c4bc6"), "address" : { "building" : "2300", "coord" : [ -73.8786113, 40.8502883 ], "rua" : "Southern Boulevard", "zipcode" : "10460" }, "localidade" : "Bronx", "gastronomia" : "American", "grades" : [ { "date" : ISODate("2014-05-21T00:00:00Z"), "grade" : "A", "score" : 5 }, { "date" : ISODate("2013-05-28T00:00:00Z"), "grade" : "A", "score" : 3 }, { "date" : ISODate("2012-06-18T00:00:00Z"), "grade" : "A", "score" : 4 }, { "date" : ISODate("2011-06-07T00:00:00Z"), "grade" : "A", "score" : 9 } ], "nome" : "African Market (Baboon Cafe)", "restaurant_id" : "40368026" } { "_id" : ObjectId("6712e9eb8c188b676f5c4bc5"), "address" : { "building" : "2300", "coord" : [ -73.8786113, 40.8502883 ], "rua" : "Southern Boulevard", "zipcode" : "10460" }, "localidade" : "Bronx", "gastronomia" : "African", "grades" : [ { "date" : ISODate("2014-05-21T00:00:00Z"), "grade" : "A", "score" : 8 }, { "date" : ISODate("2013-06-01T00:00:00Z"), "grade" : "A", "score" : 6 }, { "date" : ISODate("2012-06-12T00:00:00Z"), "grade" : "A", "score" : 0 }, { "date" : ISODate("2011-06-08T00:00:00Z"), "grade" : "A", "score" : 0 } ], "nome" : "African Terrace", "restaurant_id" : "40368021" } { "_id" : ObjectId("6712e9eb8c188b676f5c5075"), "address" : { "building" : "3825", "coord" : [ -73.86267, 40.884484 ], "rua" : "White Plains Road", "zipcode" : "10467" }, "localidade" : "Bronx", "gastronomia" : "Caribbean", "grades" : [ { "date" : ISODate("2014-11-06T00:00:00Z"), "grade" : "Z", "score" : 20 }, { "date" : ISODate("2014-06-16T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2013-10-21T00:00:00Z"), "grade" : "B", "score" : 15 }, { "date" : ISODate("2013-05-20T00:00:00Z"), "grade" : "B", "score" : 22 }, { "date" : ISODate("2012-04-17T00:00:00Z"), "grade" : "A", "score" : 10 } ], "nome" : "Al Cholo Bakery", "restaurant_id" : "40424273" } { "_id" : ObjectId("6712e9eb8c188b676f5c5638"), "address" : { "building" : "4220", "coord" : [ -73.85672319999999, 40.8939927 ], "rua" : "White Plains Road", "zipcode" : "10466" }, "localidade" : "Bronx", "gastronomia" : "Caribbean", "grades" : [ { "date" : ISODate("2014-11-06T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2013-11-06T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2013-05-31T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2012-11-27T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2012-06-28T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2012-01-19T00:00:00Z"), "grade" : "A", "score" : 13 } ], "nome" : "Ali'S Roti Shop", "restaurant_id" : "40738028" } { "_id" : ObjectId("6712e9eb8c188b676f5c5042"), "address" : { "building" : "730", "coord" : [ -73.89954829999999, 40.8164378 ], "rua" : "Kelly Street", "zipcode" : "10455" }, "localidade" : "Bronx", "gastronomia" : "American", "grades" : [ { "date" : ISODate("2015-01-20T00:00:00Z"), "grade" : "Not Yet Graded", "score" : 4 } ], "nome" : "Ambassador Diner", "restaurant_id" : "40403946" } { "_id" : ObjectId("6712e9eb8c188b676f5c525e"), "address" : { "building" : "445", "coord" : [ -73.9049794, 40.8874509 ], "rua" : "West 238 Street", "zipcode" : "10463" }, "localidade" : "Bronx", "gastronomia" : "American", "grades" : [ { "date" : ISODate("2014-03-20T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2013-08-15T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2012-08-01T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2012-03-27T00:00:00Z"), "grade" : "A", "score" : 12 } ], "nome" : "An Beal Bocht Cafe", "restaurant_id" : "40570634" } { "_id" : ObjectId("6712e9eb8c188b676f5c55f9"), "address" : { "building" : "4315", "coord" : [ -73.8676548, 40.8992003 ], "rua" : "Katonah Ave", "zipcode" : "10470" }, "localidade" : "Bronx", "gastronomia" : "Bakery", "grades" : [ { "date" : ISODate("2014-09-22T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2013-10-08T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2013-05-29T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2012-12-12T00:00:00Z"), "grade" : "A", "score" : 0 }, { "date" : ISODate("2011-12-06T00:00:00Z"), "grade" : "A", "score" : 7 } ], "nome" : "Angelica'S Bakery", "restaurant_id" : "40730301" } { "_id" : ObjectId("6712e9eb8c188b676f5c56ac"), "address" : { "building" : "2276", "coord" : [ -73.8263328, 40.8662088 ], "rua" : "Bartow Avenue", "zipcode" : "10475" }, "localidade" : "Bronx", "gastronomia" : "American", "grades" : [ { "date" : ISODate("2015-01-14T00:00:00Z"), "grade" : "A", "score" : 3 }, { "date" : ISODate("2014-08-28T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2013-08-09T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2013-03-06T00:00:00Z"), "grade" : "A", "score" : 5 }, { "date" : ISODate("2012-02-02T00:00:00Z"), "grade" : "A", "score" : 11 } ], "nome" : "Applebee'S Neighborhood Grill & Bar", "restaurant_id" : "40752494" } { "_id" : ObjectId("6712e9eb8c188b676f5c4cd9"), "address" : { "building" : "4277", "coord" : [ -73.8675389, 40.8977829 ], "rua" : "Katonah Ave", "zipcode" : "10470" }, "localidade" : "Bronx", "gastronomia" : "Irish", "grades" : [ { "date" : ISODate("2014-10-06T00:00:00Z"), "grade" : "A", "score" : 2 }, { "date" : ISODate("2013-10-16T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2013-04-30T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2012-04-30T00:00:00Z"), "grade" : "A", "score" : 8 }, { "date" : ISODate("2011-11-01T00:00:00Z"), "grade" : "A", "score" : 11 } ], "nome" : "Aqueduct North", "restaurant_id" : "40379894" } { "_id" : ObjectId("6712e9eb8c188b676f5c5262"), "address" : { "building" : "1511", "coord" : [ -73.86362500000001, 40.8381664 ], "rua" : "White Plains Road", "zipcode" : "10462" }, "localidade" : "Bronx", "gastronomia" : "American", "grades" : [ { "date" : ISODate("2014-06-25T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2013-06-03T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2012-06-06T00:00:00Z"), "grade" : "A", "score" : 13 } ], "nome" : "Archer Sports Bar", "restaurant_id" : "40571081" } { "_id" : ObjectId("6712e9eb8c188b676f5c50ec"), "address" : { "building" : "394", "coord" : [ -73.78706799999999, 40.8496359 ], "rua" : "City Island Avenue", "zipcode" : "10464" }, "localidade" : "Bronx", "gastronomia" : "Italian", "grades" : [ { "date" : ISODate("2014-05-22T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2013-12-11T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2013-03-28T00:00:00Z"), "grade" : "B", "score" : 22 }, { "date" : ISODate("2012-08-07T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2012-01-18T00:00:00Z"), "grade" : "A", "score" : 13 } ], "nome" : "Artie'S", "restaurant_id" : "40515670" } { "_id" : ObjectId("6712e9eb8c188b676f5c4d85"), "address" : { "building" : "5189A", "coord" : [ -73.91039789999999, 40.8745536 ], "rua" : "Broadway", "zipcode" : "10463" }, "localidade" : "Bronx", "gastronomia" : "Pizza", "grades" : [ { "date" : ISODate("2015-01-09T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2014-06-23T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2013-10-16T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2013-05-15T00:00:00Z"), "grade" : "C", "score" : 13 }, { "date" : ISODate("2012-09-20T00:00:00Z"), "grade" : "A", "score" : 4 }, { "date" : ISODate("2012-04-23T00:00:00Z"), "grade" : "A", "score" : 12 } ], "nome" : "Arturo'S Pizza", "restaurant_id" : "40387399" } { "_id" : ObjectId("6712e9eb8c188b676f5c505d"), "address" : { "building" : "670", "coord" : [ -73.8851025, 40.8541951 ], "rua" : "East 187 Street", "zipcode" : "10458" }, "localidade" : "Bronx", "gastronomia" : "Italian", "grades" : [ { "date" : ISODate("2014-05-29T00:00:00Z"), "grade" : "A", "score" : 8 }, { "date" : ISODate("2014-01-02T00:00:00Z"), "grade" : "A", "score" : 2 }, { "date" : ISODate("2012-12-07T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2011-11-29T00:00:00Z"), "grade" : "A", "score" : 13 } ], "nome" : "Artuso Pastry Shop", "restaurant_id" : "40423571" } { "_id" : ObjectId("6712e9eb8c188b676f5c56d0"), "address" : { "building" : "5500", "coord" : [ -73.90567390000001, 40.8766056 ], "rua" : "Broadway", "zipcode" : "10463" }, "localidade" : "Bronx", "gastronomia" : "Juice, Smoothies, Fruit Salads", "grades" : [ { "date" : ISODate("2014-09-16T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2013-09-19T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2012-09-20T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2011-10-06T00:00:00Z"), "grade" : "A", "score" : 13 } ], "nome" : "Astral Fitness & Wellness", "restaurant_id" : "40760469" } { "_id" : ObjectId("6712e9eb8c188b676f5c4dc0"), "address" : { "building" : "2214", "coord" : [ -73.82328319999999, 40.8689401 ], "rua" : "Bartow Ave", "zipcode" : "10475" }, "localidade" : "Bronx", "gastronomia" : "Delicatessen", "grades" : [ { "date" : ISODate("2014-10-18T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2014-05-02T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2013-10-30T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2013-05-30T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2013-02-12T00:00:00Z"), "grade" : "B", "score" : 18 }, { "date" : ISODate("2012-01-18T00:00:00Z"), "grade" : "A", "score" : 7 } ], "nome" : "Bagel Cafe", "restaurant_id" : "40389011" } // 6. Liste todos os restaurantes que tenham pelo menos um score superior a 85. db.restaurants.find({"grades.score": {$gt: 85}}) { "_id" : ObjectId("6712e9eb8c188b676f5c4c4e"), "address" : { "building" : "65", "coord" : [ -73.9782725, 40.7624022 ], "rua" : "West 54 Street", "zipcode" : "10019" }, "localidade" : "Manhattan", "gastronomia" : "American", "grades" : [ { "date" : ISODate("2014-08-22T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2014-03-28T00:00:00Z"), "grade" : "C", "score" : 131 }, { "date" : ISODate("2013-09-25T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2013-04-08T00:00:00Z"), "grade" : "B", "score" : 25 }, { "date" : ISODate("2012-10-15T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2011-10-19T00:00:00Z"), "grade" : "A", "score" : 13 } ], "nome" : "Murals On 54/Randolphs'S", "restaurant_id" : "40372466" } { "_id" : ObjectId("6712e9eb8c188b676f5c4cec"), "address" : { "building" : "345", "coord" : [ -73.9864626, 40.7266739 ], "rua" : "East 6 Street", "zipcode" : "10003" }, "localidade" : "Manhattan", "gastronomia" : "Indian", "grades" : [ { "date" : ISODate("2014-09-15T00:00:00Z"), "grade" : "A", "score" : 5 }, { "date" : ISODate("2014-01-14T00:00:00Z"), "grade" : "A", "score" : 8 }, { "date" : ISODate("2013-05-30T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2013-04-24T00:00:00Z"), "grade" : "P", "score" : 2 }, { "date" : ISODate("2012-10-01T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2012-04-06T00:00:00Z"), "grade" : "C", "score" : 92 }, { "date" : ISODate("2011-11-03T00:00:00Z"), "grade" : "C", "score" : 41 } ], "nome" : "Gandhi", "restaurant_id" : "40381295" } { "_id" : ObjectId("6712e9eb8c188b676f5c4e51"), "address" : { "building" : "130", "coord" : [ -73.984758, 40.7457939 ], "rua" : "Madison Avenue", "zipcode" : "10016" }, "localidade" : "Manhattan", "gastronomia" : "Pizza/Italian", "grades" : [ { "date" : ISODate("2014-12-24T00:00:00Z"), "grade" : "Z", "score" : 31 }, { "date" : ISODate("2014-06-17T00:00:00Z"), "grade" : "C", "score" : 98 }, { "date" : ISODate("2013-12-12T00:00:00Z"), "grade" : "C", "score" : 32 }, { "date" : ISODate("2013-05-22T00:00:00Z"), "grade" : "B", "score" : 21 }, { "date" : ISODate("2012-05-02T00:00:00Z"), "grade" : "A", "score" : 11 } ], "nome" : "Bella Napoli", "restaurant_id" : "40393488" } { "_id" : ObjectId("6712e9eb8c188b676f5c56bb"), "address" : { "building" : "", "coord" : [ -74.0163793, 40.7167671 ], "rua" : "Hudson River", "zipcode" : "10282" }, "localidade" : "Manhattan", "gastronomia" : "American", "grades" : [ { "date" : ISODate("2014-06-27T00:00:00Z"), "grade" : "C", "score" : 89 }, { "date" : ISODate("2013-06-06T00:00:00Z"), "grade" : "A", "score" : 6 }, { "date" : ISODate("2012-06-19T00:00:00Z"), "grade" : "A", "score" : 13 } ], "nome" : "West 79Th Street Boat Basin Cafe", "restaurant_id" : "40756344" } // 7. Encontre os restaurantes que obtiveram uma ou mais pontuações (score) entre [80 e 100]. db.restaurants.find({"grades": {$elemMatch: { "score": {$gte: 80, $lte: 100}}}}) { "_id" : ObjectId("6712e9eb8c188b676f5c4cec"), "address" : { "building" : "345", "coord" : [ -73.9864626, 40.7266739 ], "rua" : "East 6 Street", "zipcode" : "10003" }, "localidade" : "Manhattan", "gastronomia" : "Indian", "grades" : [ { "date" : ISODate("2014-09-15T00:00:00Z"), "grade" : "A", "score" : 5 }, { "date" : ISODate("2014-01-14T00:00:00Z"), "grade" : "A", "score" : 8 }, { "date" : ISODate("2013-05-30T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2013-04-24T00:00:00Z"), "grade" : "P", "score" : 2 }, { "date" : ISODate("2012-10-01T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2012-04-06T00:00:00Z"), "grade" : "C", "score" : 92 }, { "date" : ISODate("2011-11-03T00:00:00Z"), "grade" : "C", "score" : 41 } ], "nome" : "Gandhi", "restaurant_id" : "40381295" } { "_id" : ObjectId("6712e9eb8c188b676f5c4e51"), "address" : { "building" : "130", "coord" : [ -73.984758, 40.7457939 ], "rua" : "Madison Avenue", "zipcode" : "10016" }, "localidade" : "Manhattan", "gastronomia" : "Pizza/Italian", "grades" : [ { "date" : ISODate("2014-12-24T00:00:00Z"), "grade" : "Z", "score" : 31 }, { "date" : ISODate("2014-06-17T00:00:00Z"), "grade" : "C", "score" : 98 }, { "date" : ISODate("2013-12-12T00:00:00Z"), "grade" : "C", "score" : 32 }, { "date" : ISODate("2013-05-22T00:00:00Z"), "grade" : "B", "score" : 21 }, { "date" : ISODate("2012-05-02T00:00:00Z"), "grade" : "A", "score" : 11 } ], "nome" : "Bella Napoli", "restaurant_id" : "40393488" } { "_id" : ObjectId("6712e9eb8c188b676f5c5549"), "address" : { "building" : "243", "coord" : [ -73.9889479, 40.7568894 ], "rua" : "West 42 Street", "zipcode" : "10036" }, "localidade" : "Manhattan", "gastronomia" : "American", "grades" : [ { "date" : ISODate("2014-10-31T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2014-05-16T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2013-11-19T00:00:00Z"), "grade" : "A", "score" : 5 }, { "date" : ISODate("2013-03-25T00:00:00Z"), "grade" : "B", "score" : 19 }, { "date" : ISODate("2012-09-05T00:00:00Z"), "grade" : "B", "score" : 26 }, { "date" : ISODate("2012-04-10T00:00:00Z"), "grade" : "C", "score" : 49 }, { "date" : ISODate("2011-11-21T00:00:00Z"), "grade" : "C", "score" : 80 } ], "nome" : "B.B. Kings", "restaurant_id" : "40704853" } { "_id" : ObjectId("6712e9eb8c188b676f5c56bb"), "address" : { "building" : "", "coord" : [ -74.0163793, 40.7167671 ], "rua" : "Hudson River", "zipcode" : "10282" }, "localidade" : "Manhattan", "gastronomia" : "American", "grades" : [ { "date" : ISODate("2014-06-27T00:00:00Z"), "grade" : "C", "score" : 89 }, { "date" : ISODate("2013-06-06T00:00:00Z"), "grade" : "A", "score" : 6 }, { "date" : ISODate("2012-06-19T00:00:00Z"), "grade" : "A", "score" : 13 } ], "nome" : "West 79Th Street Boat Basin Cafe", "restaurant_id" : "40756344" } // 8. Indique os restaurantes com latitude inferior a -95,7. db.restaurants.find({ "address.coord.0": { $lt: -95.7 } }) { "_id" : ObjectId("6712e9eb8c188b676f5c5135"), "address" : { "building" : "3707", "coord" : [ -101.8945214, 33.5197474 ], "rua" : "82 Street", "zipcode" : "11372" }, "localidade" : "Queens", "gastronomia" : "American", "grades" : [ { "date" : ISODate("2014-06-04T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2013-11-07T00:00:00Z"), "grade" : "B", "score" : 19 }, { "date" : ISODate("2013-05-17T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2012-08-29T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2012-04-03T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2011-11-16T00:00:00Z"), "grade" : "A", "score" : 7 } ], "nome" : "Burger King", "restaurant_id" : "40534067" } { "_id" : ObjectId("6712e9eb8c188b676f5c54b0"), "address" : { "building" : "15259", "coord" : [ -119.6368672, 36.2504996 ], "rua" : "10 Avenue", "zipcode" : "11357" }, "localidade" : "Queens", "gastronomia" : "Italian", "grades" : [ { "date" : ISODate("2014-09-04T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2014-03-26T00:00:00Z"), "grade" : "A", "score" : 8 }, { "date" : ISODate("2013-03-04T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2012-09-27T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2012-04-20T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2011-11-23T00:00:00Z"), "grade" : "C", "score" : 34 } ], "nome" : "Cascarino'S", "restaurant_id" : "40668681" } { "_id" : ObjectId("6712e9eb8c188b676f5c594c"), "address" : { "building" : "60", "coord" : [ -111.9975205, 42.0970258 ], "rua" : "West Side Highway", "zipcode" : "10006" }, "localidade" : "Manhattan", "gastronomia" : "Japanese", "grades" : [ { "date" : ISODate("2014-03-20T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2013-06-28T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2012-07-05T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2011-07-27T00:00:00Z"), "grade" : "A", "score" : 2 } ], "nome" : "Sports Center At Chelsea Piers (Sushi Bar)", "restaurant_id" : "40882356" } //9. Indique os restaurantes que não têm gastronomia "American", tiveram uma (ou mais) pontuação superior a 70 e estão numa latitude inferior a -65. db.restaurants.find({"gastronomia": { $ne: "American" }, $and: [ { "grades.score": { $gt: 70 } }, { "address.coord.0": { $lt: -65 } }]}) { "_id" : ObjectId("6712e9eb8c188b676f5c4cec"), "address" : { "building" : "345", "coord" : [ -73.9864626, 40.7266739 ], "rua" : "East 6 Street", "zipcode" : "10003" }, "localidade" : "Manhattan", "gastronomia" : "Indian", "grades" : [ { "date" : ISODate("2014-09-15T00:00:00Z"), "grade" : "A", "score" : 5 }, { "date" : ISODate("2014-01-14T00:00:00Z"), "grade" : "A", "score" : 8 }, { "date" : ISODate("2013-05-30T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2013-04-24T00:00:00Z"), "grade" : "P", "score" : 2 }, { "date" : ISODate("2012-10-01T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2012-04-06T00:00:00Z"), "grade" : "C", "score" : 92 }, { "date" : ISODate("2011-11-03T00:00:00Z"), "grade" : "C", "score" : 41 } ], "nome" : "Gandhi", "restaurant_id" : "40381295" } { "_id" : ObjectId("6712e9eb8c188b676f5c4e51"), "address" : { "building" : "130", "coord" : [ -73.984758, 40.7457939 ], "rua" : "Madison Avenue", "zipcode" : "10016" }, "localidade" : "Manhattan", "gastronomia" : "Pizza/Italian", "grades" : [ { "date" : ISODate("2014-12-24T00:00:00Z"), "grade" : "Z", "score" : 31 }, { "date" : ISODate("2014-06-17T00:00:00Z"), "grade" : "C", "score" : 98 }, { "date" : ISODate("2013-12-12T00:00:00Z"), "grade" : "C", "score" : 32 }, { "date" : ISODate("2013-05-22T00:00:00Z"), "grade" : "B", "score" : 21 }, { "date" : ISODate("2012-05-02T00:00:00Z"), "grade" : "A", "score" : 11 } ], "nome" : "Bella Napoli", "restaurant_id" : "40393488" } { "_id" : ObjectId("6712e9eb8c188b676f5c4e61"), "address" : { "building" : "101", "coord" : [ -73.9243061, 40.8276297 ], "rua" : "East 161 Street", "zipcode" : "10451" }, "localidade" : "Bronx", "gastronomia" : "Latin (Cuban, Dominican, Puerto Rican, South & Central American)", "grades" : [ { "date" : ISODate("2014-04-10T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2013-10-01T00:00:00Z"), "grade" : "A", "score" : 6 }, { "date" : ISODate("2013-04-11T00:00:00Z"), "grade" : "B", "score" : 25 }, { "date" : ISODate("2012-10-25T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2012-10-10T00:00:00Z"), "grade" : "P", "score" : 12 }, { "date" : ISODate("2012-05-25T00:00:00Z"), "grade" : "B", "score" : 14 }, { "date" : ISODate("2011-09-14T00:00:00Z"), "grade" : "B", "score" : 26 }, { "date" : ISODate("2011-04-25T00:00:00Z"), "grade" : "C", "score" : 76 } ], "nome" : "El Molino Rojo Restaurant", "restaurant_id" : "40393688" } { "_id" : ObjectId("6712e9eb8c188b676f5c4fad"), "address" : { "building" : "289", "coord" : [ -73.94610279999999, 40.7137587 ], "rua" : "Manhattan Avenue", "zipcode" : "11211" }, "localidade" : "Brooklyn", "gastronomia" : "Bakery", "grades" : [ { "date" : ISODate("2014-03-19T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2013-10-10T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2013-05-07T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2012-09-11T00:00:00Z"), "grade" : "B", "score" : 18 }, { "date" : ISODate("2012-04-18T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2011-09-27T00:00:00Z"), "grade" : "A", "score" : 8 }, { "date" : ISODate("2011-05-03T00:00:00Z"), "grade" : "C", "score" : 77 } ], "nome" : "Fortunato Bros Cafe & Bakery", "restaurant_id" : "40400561" } { "_id" : ObjectId("6712e9eb8c188b676f5c55d5"), "address" : { "building" : "231", "coord" : [ -73.9772294, 40.7527262 ], "rua" : "Grand Central Station", "zipcode" : "10017" }, "localidade" : "Manhattan", "gastronomia" : "Italian", "grades" : [ { "date" : ISODate("2015-01-07T00:00:00Z"), "grade" : "Z", "score" : 20 }, { "date" : ISODate("2014-07-03T00:00:00Z"), "grade" : "B", "score" : 14 }, { "date" : ISODate("2013-12-21T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2013-05-17T00:00:00Z"), "grade" : "C", "score" : 76 }, { "date" : ISODate("2012-04-20T00:00:00Z"), "grade" : "A", "score" : 12 } ], "nome" : "Two Boots Grand Central", "restaurant_id" : "40725591" } //10. Liste o restaurant_id, o nome, a localidade e gastronomia dos restaurantes cujo nome começam por "Wil". db.restaurants.find({ "nome": /^Wil/ }, { "restaurant_id": 1, "nome": 1, "localidade": 1, "gastronomia": 1, "_id": 0 }) { "localidade" : "Brooklyn", "gastronomia" : "Delicatessen", "nome" : "Wilken'S Fine Food", "restaurant_id" : "40356483" } { "localidade" : "Bronx", "gastronomia" : "American", "nome" : "Wild Asia", "restaurant_id" : "40357217" } { "localidade" : "Bronx", "gastronomia" : "Pizza", "nome" : "Wilbel Pizza", "restaurant_id" : "40871979" } //11. Liste o nome, a localidade e a gastronomia dos restaurantes que pertencem ao Bronx e cuja gastronomia é do tipo "American" ou "Chinese". db.restaurants.find({"localidade": "Bronx", $or: [{ "gastronomia": "American" },{ "gastronomia": "Chinese" }]}, {"nome": 1, "localidade": 1, "gastronomia": 1, "_id": 0}) { "localidade" : "Bronx", "gastronomia" : "American", "nome" : "Wild Asia" } { "localidade" : "Bronx", "gastronomia" : "Chinese", "nome" : "Happy Garden" } { "localidade" : "Bronx", "gastronomia" : "Chinese", "nome" : "Happy Garden" } { "localidade" : "Bronx", "gastronomia" : "American", "nome" : "Manhem Club" } { "localidade" : "Bronx", "gastronomia" : "American", "nome" : "The New Starling Athletic Club Of The Bronx" } { "localidade" : "Bronx", "gastronomia" : "American", "nome" : "Yankee Tavern" } { "localidade" : "Bronx", "gastronomia" : "American", "nome" : "The Punch Bowl" } (...) //12. Liste o restaurant_id, o nome, a localidade e a gastronomia dos restaurantes localizados em "Staten Island", "Queens", ou "Brooklyn". db.restaurants.find({"localidade": { $in: ["Staten Island", "Queens", "Brooklyn"]}}, { "restaurant_id": 1, "nome": 1, "localidade": 1, "gastronomia": 1, "_id": 0}) { "localidade" : "Brooklyn", "gastronomia" : "American", "nome" : "Riviera Caterer", "restaurant_id" : "40356018" } { "localidade" : "Brooklyn", "gastronomia" : "Hamburgers", "nome" : "Wendy'S", "restaurant_id" : "30112340" } { "localidade" : "Queens", "gastronomia" : "Jewish/Kosher", "nome" : "Tov Kosher Kitchen", "restaurant_id" : "40356068" } { "localidade" : "Staten Island", "gastronomia" : "Jewish/Kosher", "nome" : "Kosher Island", "restaurant_id" : "40356442" } { "localidade" : "Queens", "gastronomia" : "American", "nome" : "Brunos On The Boulevard", "restaurant_id" : "40356151" } { "localidade" : "Brooklyn", "gastronomia" : "Delicatessen", "nome" : "Wilken'S Fine Food", "restaurant_id" : "40356483" } { "localidade" : "Brooklyn", "gastronomia" : "Chinese", "nome" : "May May Kitchen", "restaurant_id" : "40358429" } { "localidade" : "Brooklyn", "gastronomia" : "Ice Cream, Gelato, Yogurt, Ices", "nome" : "Taste The Tropics Ice Cream", "restaurant_id" : "40356731" } //13. Liste o nome, a localidade, o score e gastronomia dos restaurantes que alcançaram sempre pontuações inferiores ou igual a 3 db.restaurants.find({"grades.score": { $not: { $gt: 3}}},{"nome": 1, "localidade": 1, "gastronomia": 1, "grades.score": 1 ,"_id": 0 }) { "localidade" : "Brooklyn", "gastronomia" : "Hamburgers", "grades" : [ { "score" : 2 }, { "score" : 3 }, { "score" : 0 } ], "nome" : "White Castle" } { "localidade" : "Manhattan", "gastronomia" : "Café/Coffee/Tea", "grades" : [ { "score" : 2 }, { "score" : 2 }, { "score" : 2 }, { "score" : 2 } ], "nome" : "Cafe Madison" } { "localidade" : "Manhattan", "gastronomia" : "American", "grades" : [ { "score" : 0 }, { "score" : 3 }, { "score" : 2 } ], "nome" : "Citibank Executive Conference Center" } { "localidade" : "Manhattan", "gastronomia" : "American", "grades" : [ { "score" : 3 }, { "score" : 2 }, { "score" : 2 }, { "score" : 0 } ], "nome" : "Kenyon & Kenyon Cafeteria" } { "localidade" : "Manhattan", "gastronomia" : "American", "grades" : [ { "score" : 2 }, { "score" : 0 } ], "nome" : "Gold Bar B" } { "localidade" : "Manhattan", "gastronomia" : "American", "grades" : [ { "score" : 0 }, { "score" : 0 }, { "score" : 2 } ], "nome" : "Circle In The Square Theatre" } { "localidade" : "Brooklyn", "gastronomia" : "American", "grades" : [ { "score" : 3 } ], "nome" : "Stand # 210" } //14. Liste o nome e as avaliações dos restaurantes que obtiveram uma avaliação com um grade "A", um score 10 na data "2014-08-11T00: 00: 00Z" (ISODATE) db.restaurants.find({'grades':{'$elemMatch': {grade: 'A', score: 10, date: ISODate("2014-08-11T00:00:00Z")}}},{'grades.grade': 1, nome: 1, "_id": 0}) { "grades" : [ { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" } ], "nome" : "Serendipity 3" } { "grades" : [ { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" } ], "nome" : "Mutual Of America" } { "grades" : [ { "grade" : "A" }, { "grade" : "B" }, { "grade" : "C" }, { "grade" : "C" }, { "grade" : "C" } ], "nome" : "Udon West" } { "grades" : [ { "grade" : "A" }, { "grade" : "A" }, { "grade" : "B" }, { "grade" : "A" }, { "grade" : "A" } ], "nome" : "Gene'S Coffee Shop" } { "grades" : [ { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "P" } ], "nome" : "Union Cafe Restaurant" } { "grades" : [ { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" } ], "nome" : "Jojo'S Pizza" } //15. Liste o restaurant_id, o nome e os score dos restaurantes nos quais a segunda avaliação foi grade "A" e ocorreu em ISODATE "2014-08-11T00: 00: 00Z". db.restaurants.find({'grades.1.grade': {$eq: 'A'}, 'grades.1.date': {$eq: ISODate("2014-08-11T00:00:00Z")}}, {restaurant_id: 1, nome: 1, 'grades.score': 1, "_id": 0}) { "grades" : [ { "score" : 10 }, { "score" : 9 }, { "score" : 13 }, { "score" : 10 }, { "score" : 11 } ], "nome" : "Club Macanudo (Cigar Bar)", "restaurant_id" : "40526406" } { "grades" : [ { "score" : 9 }, { "score" : 10 }, { "score" : 22 }, { "score" : 5 }, { "score" : 11 } ], "nome" : "Gene'S Coffee Shop", "restaurant_id" : "40614916" } //16. Liste o restaurant_id, o nome, o endereço (address) dos restaurantes onde o 2º elemento da matriz de coordenadas (coord) tem um valor superior a 42 e inferior ou igual a 52. db.restaurants.find({$and: [{'address.coord.1': {$gt:42}},{'address.coord.1': {$lte:52}}]},{restaurant_id: 1, address: 1, nome: 1, "_id":0}) { "address" : { "building" : "47", "coord" : [ -78.877224, 42.89546199999999 ], "rua" : "Broadway @ Trinity Pl", "zipcode" : "10006" }, "nome" : "T.G.I. Friday'S", "restaurant_id" : "40387990" } { "address" : { "building" : "1", "coord" : [ -0.7119979, 51.6514664 ], "rua" : "Pennplaza E, Penn Sta", "zipcode" : "10001" }, "nome" : "T.G.I. Fridays", "restaurant_id" : "40388936" } { "address" : { "building" : "3000", "coord" : [ -87.86567699999999, 42.61150920000001 ], "rua" : "47 Avenue", "zipcode" : "11101" }, "nome" : "Di Luvio'S Deli", "restaurant_id" : "40402284" } { "address" : { "building" : "21972199", "coord" : [ -78.589606, 42.8912372 ], "rua" : "Broadway", "zipcode" : "10024" }, "nome" : "La Caridad 78", "restaurant_id" : "40568285" } { "address" : { "building" : "7981", "coord" : [ -84.9751215, 45.4713351 ], "rua" : "Hoyt Street", "zipcode" : "11201" }, "nome" : "Bijan'S", "restaurant_id" : "40876618" } { "address" : { "building" : "0", "coord" : [ -88.0778799, 42.4154769 ], "rua" : "& Grand Central", "zipcode" : "10017" }, "nome" : "Hyatt, Ny Central/Room Service", "restaurant_id" : "40879243" } { "address" : { "building" : "60", "coord" : [ -111.9975205, 42.0970258 ], "rua" : "West Side Highway", "zipcode" : "10006" }, "nome" : "Sports Center At Chelsea Piers (Sushi Bar)", "restaurant_id" : "40882356" } //17. Liste nome, gastronomia e localidade de todos os restaurantes ordenando por ordem crescente da gastronomia e, em segundo, por ordem decrescente de localidade. db.restaurants.find({}, {nome: 1,gastronomia: 1, localidade: 1, "_id": 0}).sort({gastronomia: 1, localidade: -1}) { "localidade" : "Manhattan", "gastronomia" : "Afghan", "nome" : "Khyber Pass" } { "localidade" : "Manhattan", "gastronomia" : "Afghan", "nome" : "Afghan Kebab House" } { "localidade" : "Manhattan", "gastronomia" : "Afghan", "nome" : "Ariana Kebab House" } { "localidade" : "Manhattan", "gastronomia" : "Afghan", "nome" : "Afghan Kebab House #1" } { "localidade" : "Queens", "gastronomia" : "African", "nome" : "Africana Restaurant" } { "localidade" : "Brooklyn", "gastronomia" : "African", "nome" : "Madiba" } { "localidade" : "Bronx", "gastronomia" : "African", "nome" : "Ebe Ye Yie African Restaurant" } { "localidade" : "Bronx", "gastronomia" : "African", "nome" : "African Terrace" } { "localidade" : "Staten Island", "gastronomia" : "American", "nome" : "Campus Center Cafeteria" } (...) //18. Liste nome, localidade, grade e gastronomia de todos os restaurantes localizados em Brooklyn que não incluem gastronomia "American" e obtiveram uma classificação (grade) "A". Deve apresentá-los por ordem decrescente de gastronomia. db.restaurants.find({ $and: [{localidade: 'Brooklyn'}, {gastronomia: { $ne: 'American'}}, {'grades.grade': 'A'}]}, {nome: 1, localidade: 1, 'grades.grade': 1, gastronomia: 1, _id: 0}).sort({gastronomia: -1}); { "localidade" : "Brooklyn", "gastronomia" : "Vegetarian", "grades" : [ { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "C" } ], "nome" : "Original Vegetarian Restaurant" } { "localidade" : "Brooklyn", "gastronomia" : "Vegetarian", "grades" : [ { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "C" }, { "grade" : "A" } ], "nome" : "Strictly Vegetarian" } { "localidade" : "Brooklyn", "gastronomia" : "Turkish", "grades" : [ { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" } ], "nome" : "Istanbul Restaurant" } { "localidade" : "Brooklyn", "gastronomia" : "Turkish", "grades" : [ { "grade" : "A" }, { "grade" : "B" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "C" }, { "grade" : "A" }, { "grade" : "A" } ], "nome" : "Sahara Restaurant" } { "localidade" : "Brooklyn", "gastronomia" : "Turkish", "grades" : [ { "grade" : "A" }, { "grade" : "A" }, { "grade" : "B" }, { "grade" : "A" }, { "grade" : "B" }, { "grade" : "A" } ], "nome" : "Memo Shish Kebab" } { "localidade" : "Brooklyn", "gastronomia" : "Thai", "grades" : [ { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "C" }, { "grade" : "A" } ], "nome" : "Ott Thai Cuisine" } { "localidade" : "Brooklyn", "gastronomia" : "Thai", "grades" : [ { "grade" : "A" }, { "grade" : "B" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" } ], "nome" : "Joya" } (...) //19. Indique o número total de avaliações (numGrades) na coleção. db.restaurants.aggregate([ { $project: { numGrades: { $size: "$grades" } } }, { $group: { _id: null, totalGrades: { $sum: "$numGrades" } } } ]) { "_id" : 0, "totalGrades" : 18142 } //20. Apresente o nome e número de avaliações (numGrades) dos 3 restaurante com mais avaliações. db.restaurants.aggregate([{$project: {nome: 1, numGrades: { $size: "$grades" }}}, {$sort: { numGrades: -1 }}, {$limit: 3}]) { "_id" : ObjectId("6712e9eb8c188b676f5c4bfa"), "nome" : "Bronx Grill", "numGrades" : 8 } { "_id" : ObjectId("6712e9eb8c188b676f5c4bf0"), "nome" : "Blue Bay Restaurant", "numGrades" : 8 } { "_id" : ObjectId("6712e9eb8c188b676f5c4b09"), "nome" : "Ho Mei Restaurant", "numGrades" : 8 } //21. Apresente o número total de avaliações (numGrades) em cada dia da semana. db.restaurants.aggregate([ { $unwind: "$grades" }, { $project: { dayOfWeek: { $dayOfWeek: { $toDate: "$grades.date" } }, grade: 1 } }, { $group: { _id: "$dayOfWeek", numGrades: { $sum: 1 } } }, { $sort: { _id: 1 } //(1 = Domingo, 7 = Sábado) } ]) { "_id" : 1, "numGrades" : 7 } { "_id" : 2, "numGrades" : 3186 } { "_id" : 3, "numGrades" : 3878 } { "_id" : 4, "numGrades" : 4118 } { "_id" : 5, "numGrades" : 3984 } { "_id" : 6, "numGrades" : 2440 } { "_id" : 7, "numGrades" : 529 } //22. Conte o total de restaurante existentes em cada localidade. db.restaurants.aggregate([{$group: {_id: "$localidade", totalRestaurantes: {$sum: 1}}}]) { "_id" : "Brooklyn", "totalRestaurantes" : 684 } { "_id" : "Queens", "totalRestaurantes" : 738 } { "_id" : "Bronx", "totalRestaurantes" : 309 } { "_id" : "Staten Island", "totalRestaurantes" : 158 } { "_id" : "Manhattan", "totalRestaurantes" : 1883 } //23. Indique os restaurantes que têm gastronomia "Portuguese", o somatório de score é superior a 50 e estão numa latitude inferior a -60. //24. Apresente o número de gastronomias diferentes na rua "Fifth Avenue" db.restaurants.aggregate([{$match: {"address.rua": "Fifth Avenue" }}, {$group: {_id: "$gastronomia"}}, {$count: "numGastronomias"}]) { "numGastronomias" : 4 } //25. Apresente o nome e o score médio (avgScore) e número de avaliações (numGrades) dos restaurantes com score médio superior a 30 desde 1-Jan-2014. //26. Indique as 5 gastronomias com o maior número de restaurantes. db.restaurants.aggregate([{$group: {_id: "$gastronomia", totalRestaurantes: { $sum: 1 }}}, {$sort: { totalRestaurantes: -1 }}, {$limit: 5}]) { "_id" : "American", "totalRestaurantes" : 1354 } { "_id" : "Chinese", "totalRestaurantes" : 754 } { "_id" : "Cafe/Coffee/Tea", "totalRestaurantes" : 680 } { "_id" : "Pizza", "totalRestaurantes" : 523 } { "_id" : "Italian", "totalRestaurantes" : 460 } //27. Indique os nomes e endereços de todos os restaurantes que têm 5 avaliações db.restaurants.find({ "grades.4": { $exists: true }, "grades.5": { $exists: false } }, { nome: 1, address: 1, _id: 0 }) { "nome" : "Wendy'S", "address" : { "building" : "469", "coord" : [ -73.961704, 40.662942 ], "rua" : "Flatbush Avenue", "zipcode" : "11225" } } { "nome" : "Bagel Cafe", "address" : { "building" : "2214", "coord" : [ -73.82328319999999, 40.8689401 ], "rua" : "Bartow Ave", "zipcode" : "10475" } } { "nome" : "Applebee'S Neighborhood Grill & Bar", "address" : { "building" : "2276", "coord" : [ -73.8263328, 40.8662088 ], "rua" : "Bartow Avenue", "zipcode" : "10475" } } (...) //28. Indique todos os restaurantes que nunca receberam uma classificação "B". db.restaurants.find({'grades.grade': {$ne: "B"}}, { nome: 1, "grades.grade": 1, _id: 0 }) { "nome" : "Dj Reynolds Pub And Restaurant", "grades" : [ { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" } ] } { "nome" : "Riviera Caterer", "grades" : [ { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" } ] } { "nome" : "Kosher Island", "grades" : [ { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" }, { "grade" : "A" } ] } (...) //29. Indique os restaurantes cujo nome contém "Pizza" e que têm mais de 3 avaliações. db.restaurants.find({nome: /Pizza/, "grades.3": {$exists: true}}, {nome: 1, _id: 0}) { "nome" : "Pizza Hut" } { "nome" : "Arturo'S Pizza" } { "nome" : "Wilbel Pizza" } (...) //30. Indique o score médio por gastronomia, ordenado decrescente. db.restaurants.aggregate([ { $unwind: "$grades" }, { $group: { _id: "$gastronomia", avgScore: { $avg: "$grades.score" } } }, { $sort: { avgScore: -1 } } ]) { "_id" : "Hawaiian", "avgScore" : 36 } { "_id" : "Brazilian", "avgScore" : 28.75 } { "_id" : "Californian", "avgScore" : 28 } { "_id" : "Barbecue", "avgScore" : 26.5 } { "_id" : "Czech", "avgScore" : 25 } (...)