Write a MongoDB query to display all the restaurant which is in the borough Bronx

Write a Query to find all the restaurant which is in the borough Bronx.


Sample Document:

{ 
  "_id" : ObjectId("6029b6e30157be18e7ee4016"), 
  "address" : {
      "building" : "1007", 
      "coord" : [
          -73.856077, 
          40.848447
      ], 
      "street" : "Morris Park Ave", 
      "zipcode" : "10462"
  }, 
  "borough" : "Bronx", 
  "cuisine" : "Bakery", 
  "grades" : [
      {
          "date" : ISODate("2014-03-03T00:00:00.000+0000"), 
          "grade" : "A", 
          "score" : 2.0
      }, 
      {
          "date" : ISODate("2013-09-11T00:00:00.000+0000"), 
          "grade" : "A", 
          "score" : 6.0
      }, 
      {
          "date" : ISODate("2013-01-24T00:00:00.000+0000"), 
          "grade" : "A", 
          "score" : 10.0
      }, 
      {
          "date" : ISODate("2011-11-23T00:00:00.000+0000"), 
          "grade" : "A", 
          "score" : 9.0
      }, 
      {
          "date" : ISODate("2011-03-10T00:00:00.000+0000"), 
          "grade" : "B", 
          "score" : 14.0
      }
  ], 
  "name" : "Morris Park Bake Shop", 
  "restaurant_id" : "30075445"
}

Approach

Query: Query to find the restaurant borough=Bronx.


db.getCollection("Restaurants").find({ "borough" : "Bronx"});

Output: 

{ 
  "_id" : ObjectId("6029b6e30157be18e7ee4016"), 
  "address" : {
      "building" : "1007", 
      "coord" : [
          -73.856077, 
          40.848447
      ], 
      "street" : "Morris Park Ave", 
      "zipcode" : "10462"
  }, 
  "borough" : "Bronx", 
  "cuisine" : "Bakery", 
  "grades" : [
      {
          "date" : ISODate("2014-03-03T00:00:00.000+0000"), 
          "grade" : "A", 
          "score" : 2.0
      }, 
      {
          "date" : ISODate("2013-09-11T00:00:00.000+0000"), 
          "grade" : "A", 
          "score" : 6.0
      }, 
      {
          "date" : ISODate("2013-01-24T00:00:00.000+0000"), 
          "grade" : "A", 
          "score" : 10.0
      }, 
      {
          "date" : ISODate("2011-11-23T00:00:00.000+0000"), 
          "grade" : "A", 
          "score" : 9.0
      }, 
      {
          "date" : ISODate("2011-03-10T00:00:00.000+0000"), 
          "grade" : "B", 
          "score" : 14.0
      }
  ], 
  "name" : "Morris Park Bake Shop", 
  "restaurant_id" : "30075445"
}
{ 
  "_id" : ObjectId("6029bd190157be18e7ee4026"), 
  "address" : {
      "building" : "2300", 
      "coord" : [
          -73.8786113, 
          40.8502883
      ], 
      "street" : "Southern Boulevard", 
      "zipcode" : "10460"
  }, 
  "borough" : "Bronx", 
  "cuisine" : "American ", 
  "grades" : [
      {
          "date" : ISODate("2014-05-28T00:00:00.000+0000"), 
          "grade" : "A", 
          "score" : 11.0
      }, 
      {
          "date" : ISODate("2013-06-19T00:00:00.000+0000"), 
          "grade" : "A", 
          "score" : 4.0
      }, 
      {
          "date" : ISODate("2012-06-15T00:00:00.000+0000"), 
          "grade" : "A", 
          "score" : 3.0
      }
  ], 
  "name" : "Wild Asia", 
  "restaurant_id" : "40357217"
}

No comments:

Post a Comment