w3resource
w3resource logo

MongoDB Exercise - Find the restaurant which belongs to the borough Bronx and prepared either American or Chinese dish


Write a MongoDB query to find the restaurants which belong to the borough Bronx and prepared either American or Chinese dish.

Structure of 'restaurants' collection :

{
  "address": {
     "building": "1007",
     "coord": [ -73.856077, 40.848447 ],
     "street": "Morris Park Ave",
     "zipcode": "10462"
  },
  "borough": "Bronx",
  "cuisine": "Bakery",
  "grades": [
     { "date": { "$date": 1393804800000 }, "grade": "A", "score": 2 },
     { "date": { "$date": 1378857600000 }, "grade": "A", "score": 6 },
     { "date": { "$date": 1358985600000 }, "grade": "A", "score": 10 },
     { "date": { "$date": 1322006400000 }, "grade": "A", "score": 9 },
     { "date": { "$date": 1299715200000 }, "grade": "B", "score": 14 }
  ],
  "name": "Morris Park Bake Shop",
  "restaurant_id": "30075445"
}

Query:

db.restaurants.find(
{ 
"borough": "Bronx" , 
$or : [
{ "cuisine" : "American " },
{ "cuisine" : "Chinese" }
] 
} 
);

Output:

{ "_id" : ObjectId("5ab23ff163b071e80805c4e6"), "address" : { "building" : "1236", "coord" : [ -73.8893654, 40.81376179999999 ], "street" : "238 Spofford Ave", "zipcode" : "10474" }, "borough" : "Bron
x", "cuisine" : "Chinese", "grades" : [ { "date" : ISODate("2013-12-30T00:00:00Z"), "grade" : "A", "score" : 8 }, { "date" : ISODate("2013-01-08T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" :
ISODate("2012-06-12T00:00:00Z"), "grade" : "B", "score" : 15 } ], "name" : "Happy Garden", "restaurant_id" : "40363289" }
{ "_id" : ObjectId("5ab23ff163b071e80805c4f9"), "address" : { "building" : "277", "coord" : [ -73.8941893, 40.8634684 ], "street" : "East Kingsbridge Road", "zipcode" : "10458" }, "borough" : "Bronx",
 "cuisine" : "Chinese", "grades" : [ { "date" : ISODate("2014-03-03T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2013-09-26T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : IS
ODate("2013-03-19T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2012-08-29T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2011-08-17T00:00:00Z"), "grade" : "A", "sco
re" : 13 } ], "name" : "Happy Garden", "restaurant_id" : "40364296" }
{ "_id" : ObjectId("5ab23ff163b071e80805ca72"), "address" : { "building" : "2459", "coord" : [ -73.8929629, 40.8601605 ], "street" : "Webster Avenue", "zipcode" : "10458" }, "borough" : "Bronx", "cuis
ine" : "Chinese", "grades" : [ { "date" : ISODate("2014-12-23T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2014-01-07T00:00:00Z"), "grade" : "A", "score" : 8 }, { "date" : ISODate("2
012-12-28T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2012-07-18T00:00:00Z"), "grade" : "A", "score" : 13 } ], "name" : "China Wok Ii", "restaurant_id" : "40510328" }
{ "_id" : ObjectId("5ab23ff163b071e80805cafd"), "address" : { "building" : "2102", "coord" : [ -73.82609699999999, 40.8687177 ], "street" : "Bartow Ave", "zipcode" : "10475" }, "borough" : "Bronx", "c
uisine" : "Chinese", "grades" : [ { "date" : ISODate("2014-08-04T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2014-02-21T00:00:00Z"), "grade" : "A", "score" : 4 }, { "date" : ISODate
("2013-05-30T00:00:00Z"), "grade" : "B", "score" : 17 }, { "date" : ISODate("2012-04-13T00:00:00Z"), "grade" : "A", "score" : 12 } ], "name" : "Dragon City", "restaurant_id" : "40529203" }
{ "_id" : ObjectId("5ab23ff163b071e80805cbab"), "address" : { "building" : "3511", "coord" : [ -73.9100876, 40.8860444 ], "street" : "Johnson Avenue", "zipcode" : "10463" }, "borough" : "Bronx", "cuis
ine" : "Chinese", "grades" : [ { "date" : ISODate("2014-07-02T00:00:00Z"), "grade" : "A", "score" : 5 }, { "date" : ISODate("2013-11-06T00:00:00Z"), "grade" : "A", "score" : 8 }, { "date" : ISODate("2
013-03-29T00:00:00Z"), "grade" : "B", "score" : 17 }, { "date" : ISODate("2012-06-20T00:00:00Z"), "grade" : "B", "score" : 27 } ], "name" : "Hunan Balcony", "restaurant_id" : "40551996" }
{ "_id" : ObjectId("5ab23ff163b071e80805cbac"), "address" : { "building" : "732", "coord" : [ -73.883128, 40.85353 ], "street" : "East  187 Street", "zipcode" : "10458" }, "borough" : "Bronx", "cuisin
e" : "Chinese", "grades" : [ { "date" : ISODate("2014-11-07T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2014-05-15T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("201
3-11-18T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2013-06-10T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2012-09-17T00:00:00Z"), "grade" : "B", "score" : 19 }
], "name" : "Great Wall Restaurant", "restaurant_id" : "40552226" }
{ "_id" : ObjectId("5ab23ff163b071e80805cc3f"), "address" : { "building" : "202", "coord" : [ -73.9164504, 40.8341845 ], "street" : "East  167 Street", "zipcode" : "10456" }, "borough" : "Bronx", "cui
sine" : "Chinese", "grades" : [ { "date" : ISODate("2014-12-10T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2013-12-12T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("
2012-12-20T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2012-08-01T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2012-03-13T00:00:00Z"), "grade" : "A", "score" : 12
 } ], "name" : "Lucky House Restaurant", "restaurant_id" : "40571587" }
{ "_id" : ObjectId("5ab23ff163b071e80805cc4d"), "address" : { "building" : "1474", "coord" : [ -73.88122729999999, 40.8281391 ], "street" : "Westchester Avenue", "zipcode" : "10472" }, "borough" : "Br
onx", "cuisine" : "Chinese", "grades" : [ { "date" : ISODate("2014-12-24T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2014-01-13T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date"
 : ISODate("2013-01-08T00:00:00Z"), "grade" : "A", "score" : 9 } ], "name" : "New Wah Kitchen", "restaurant_id" : "40573101" }
{ "_id" : ObjectId("5ab23ff163b071e80805cf0a"), "address" : { "building" : "1702", "coord" : [ -73.9137269, 40.8482958 ], "street" : "Grand Avenue", "zipcode" : "10453" }, "borough" : "Bronx", "cuisin
e" : "Chinese", "grades" : [ { "date" : ISODate("2014-04-16T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2013-04-10T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2
012-03-14T00:00:00Z"), "grade" : "A", "score" : 5 }, { "date" : ISODate("2011-09-22T00:00:00Z"), "grade" : "B", "score" : 17 } ], "name" : "New Hing Restaurant", "restaurant_id" : "40701165" }
{ "_id" : ObjectId("5ab23ff163b071e80805d0cb"), "address" : { "building" : "1811", "coord" : [ -73.8518311, 40.8504655 ], "street" : "Williamsbridge Road", "zipcode" : "10461" }, "borough" : "Bronx",
"cuisine" : "Chinese", "grades" : [ { "date" : ISODate("2014-03-26T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2013-03-05T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISOD
ate("2012-09-12T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2012-04-17T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2011-11-03T00:00:00Z"), "grade" : "A", "score"
: 4 } ], "name" : "Hong Kong Restaurant", "restaurant_id" : "40765358" }
{ "_id" : ObjectId("5ab23ff163b071e80805d156"), "address" : { "building" : "796", "coord" : [ -73.91637759999999, 40.8226814 ], "street" : "Courtlandt Avenue", "zipcode" : "10451" }, "borough" : "Bron
x", "cuisine" : "Chinese", "grades" : [ { "date" : ISODate("2014-08-15T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2013-08-27T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" :
ISODate("2013-03-06T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2012-08-14T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2012-03-21T00:00:00Z"), "grade" : "B", "sc
ore" : 17 }, { "date" : ISODate("2011-10-24T00:00:00Z"), "grade" : "A", "score" : 12 } ], "name" : "Kristy'S Restaurant", "restaurant_id" : "40804049" }
{ "_id" : ObjectId("5ab23ff163b071e80805d1d1"), "address" : { "building" : "1634", "coord" : [ -73.8306577, 40.8450232 ], "street" : "Crosby Avenue", "zipcode" : "10461" }, "borough" : "Bronx", "cuisi
ne" : "Chinese", "grades" : [ { "date" : ISODate("2014-08-08T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2013-07-23T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2
012-12-14T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2012-06-25T00:00:00Z"), "grade" : "A", "score" : 6 }, { "date" : ISODate("2011-10-03T00:00:00Z"), "grade" : "A", "score" : 8 }
 ], "name" : "East Dynasty", "restaurant_id" : "40827529" }
{ "_id" : ObjectId("5ab23ff163b071e80805d214"), "address" : { "building" : "2461", "coord" : [ -73.9041182, 40.8644648 ], "street" : "University Avenue", "zipcode" : "10468" }, "borough" : "Bronx", "c
uisine" : "Chinese", "grades" : [ { "date" : ISODate("2014-04-10T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2013-03-27T00:00:00Z"), "grade" : "A", "score" : 4 }, { "date" : ISODate
("2012-10-25T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2012-10-11T00:00:00Z"), "grade" : "P", "score" : 2 }, { "date" : ISODate("2011-11-01T00:00:00Z"), "grade" : "A", "score" :
11 }, { "date" : ISODate("2011-04-20T00:00:00Z"), "grade" : "B", "score" : 17 } ], "name" : "Lin Home Chinese Restaura", "restaurant_id" : "40842437" }
{ "_id" : ObjectId("5ab23ff163b071e80805d232"), "address" : { "building" : "70", "coord" : [ -73.9066601, 40.8592187 ], "street" : "West  183 Street", "zipcode" : "10453" }, "borough" : "Bronx", "cuis
ine" : "Chinese", "grades" : [ { "date" : ISODate("2014-12-01T00:00:00Z"), "grade" : "A", "score" : 4 }, { "date" : ISODate("2014-07-02T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("
2014-01-23T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2013-07-24T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2013-01-14T00:00:00Z"), "grade" : "A", "score" : 13
}, { "date" : ISODate("2012-07-19T00:00:00Z"), "grade" : "B", "score" : 20 }, { "date" : ISODate("2011-12-21T00:00:00Z"), "grade" : "B", "score" : 14 } ], "name" : "Peacock Restaurant", "restaurant_id
" : "40849313" }
{ "_id" : ObjectId("5ab23ff163b071e80805d266"), "address" : { "building" : "317", "coord" : [ -73.909629, 40.837446 ], "street" : "East 170 Street", "zipcode" : "10456" }, "borough" : "Bronx", "cuisin
e" : "Chinese", "grades" : [ { "date" : ISODate("2014-12-03T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2014-04-26T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("20
13-11-19T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2013-05-06T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2012-09-11T00:00:00Z"), "grade" : "A", "score" : 11 },
 { "date" : ISODate("2012-04-17T00:00:00Z"), "grade" : "A", "score" : 13 } ], "name" : "Lin'S Garden", "restaurant_id" : "40857406" }
{ "_id" : ObjectId("5ab23ff163b071e80805d37d"), "address" : { "building" : "3906", "coord" : [ -73.8612466, 40.8858379 ], "street" : "White Plains Road", "zipcode" : "10466" }, "borough" : "Bronx", "c
uisine" : "Chinese", "grades" : [ { "date" : ISODate("2014-05-12T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2013-10-07T00:00:00Z"), "grade" : "A", "score" : 6 }, { "date" : ISODate
("2012-10-04T00:00:00Z"), "grade" : "A", "score" : 10 }, { "date" : ISODate("2011-10-05T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2011-06-30T00:00:00Z"), "grade" : "A", "score" :
7 } ], "name" : "New Rainbow Restaurant", "restaurant_id" : "40899178" }
{ "_id" : ObjectId("5ab23ff163b071e80805d4a9"), "address" : { "building" : "1171", "coord" : [ -73.92330419999999, 40.83573620000001 ], "street" : "Jerome Avenue", "zipcode" : "10452" }, "borough" : "
Bronx", "cuisine" : "Chinese", "grades" : [ { "date" : ISODate("2014-10-27T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2014-05-01T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date
" : ISODate("2013-09-23T00:00:00Z"), "grade" : "A", "score" : 9 }, { "date" : ISODate("2012-09-05T00:00:00Z"), "grade" : "A", "score" : 12 } ], "name" : "Xin Hing Restaurant", "restaurant_id" : "40941
277" }
{ "_id" : ObjectId("5ab23ff163b071e80805d4ef"), "address" : { "building" : "706", "coord" : [ -73.8668038, 40.8712861 ], "street" : "Burke Avenue", "zipcode" : "10467" }, "borough" : "Bronx", "cuisine
" : "Chinese", "grades" : [ { "date" : ISODate("2014-08-11T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODate("2014-02-01T00:00:00Z"), "grade" : "A", "score" : 0 }, { "date" : ISODate("2013
-07-22T00:00:00Z"), "grade" : "B", "score" : 17 }, { "date" : ISODate("2012-12-18T00:00:00Z"), "grade" : "A", "score" : 13 }, { "date" : ISODate("2012-10-03T00:00:00Z"), "grade" : "P", "score" : 7 },
{ "date" : ISODate("2011-10-27T00:00:00Z"), "grade" : "A", "score" : 13 } ], "name" : "K & Q Restaruant", "restaurant_id" : "40947971" }
{ "_id" : ObjectId("5ab23ff163b071e80805d4f2"), "address" : { "building" : "2211", "coord" : [ -73.8513981, 40.8344605 ], "street" : "Westchester Avenue", "zipcode" : "10462" }, "borough" : "Bronx", "
cuisine" : "Chinese", "grades" : [ { "date" : ISODate("2014-10-08T00:00:00Z"), "grade" : "A", "score" : 12 }, { "date" : ISODate("2013-09-25T00:00:00Z"), "grade" : "A", "score" : 7 }, { "date" : ISODa
te("2012-09-26T00:00:00Z"), "grade" : "A", "score" : 7 } ], "name" : "China One", "restaurant_id" : "40948231" }
{ "_id" : ObjectId("5ab23ff163b071e80805d562"), "address" : { "building" : "3003", "coord" : [ -73.8821102, 40.8685226 ], "street" : "Webster Avenue", "zipcode" : "10458" }, "borough" : "Bronx", "cuis
ine" : "Chinese", "grades" : [ { "date" : ISODate("2014-05-13T00:00:00Z"), "grade" : "A", "score" : 8 }, { "date" : ISODate("2013-12-07T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("
2013-06-19T00:00:00Z"), "grade" : "A", "score" : 6 }, { "date" : ISODate("2013-01-09T00:00:00Z"), "grade" : "A", "score" : 5 }, { "date" : ISODate("2012-04-04T00:00:00Z"), "grade" : "B", "score" : 27
} ], "name" : "Great Wall", "restaurant_id" : "40962349" }
Type "it" for more

Note: This output is generated using MongoDB server version 3.6

Improve this sample solution and post your code through Disqus.