Sample MongoDB problem

Problem name

Find the restaurant

Database

MongoDB

Type

SELECT query based (Output generated by developer's solution is compared against the output generated of the evaluation query)

Problem Statement

Output the document with the restaurant_id "30075445" in the collection restaurants of the test database. You need to exclude the _id key in the document.

Use the mongo specific printjson() function which returns formatted JSON.

Sample output

{
    "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:00Z"),
            "grade" : "A",
            "score" : 2
        },
        {
            "date" : ISODate("2013-09-11T00:00:00Z"),
            "grade" : "A",
            "score" : 6
        },
        {
            "date" : ISODate("2013-01-24T00:00:00Z"),
            "grade" : "A",
            "score" : 10
        },
        {
            "date" : ISODate("2011-11-23T00:00:00Z"),
            "grade" : "A",
            "score" :9
        },
        {
            "date" : ISODate("2011-03-10T00:00:00Z"),
            "grade" : "B",
            "score" : 14
        }
    ],
    "name" : "Morris Park Bake Shop",
    "restaurant_id" : "30075445"
}

Evaluation query

conn = new Mongo()
db = conn.getDB("test")
cursor = db.restaurants.find({"restaurant_id": "30075445"}, {"_id": false})
cursor.forEach(printjson)

results matching ""

    No results matching ""