1

Hi i'm practicing mongodb and I'm stuck with a problem. I'av the following set of documents.

{
    "_id" : ObjectId("57cf9a134607674792dbad9e"),
    "address" : {
        "building" : "351",
        "coord" : [ 
            -73.9851356, 
            40.7676919
        ],
        "street" : "West   57 Street",
        "zipcode" : "10019"
    },
    "borough" : "Manhattan",
    "cuisine" : "Irish",
    "grades" : [ 
        {
            "date" : ISODate("2014-09-06T00:00:00.000Z"),
            "grade" : "A",
            "score" : 2
        }, 
        {
            "date" : ISODate("2013-07-22T00:00:00.000Z"),
            "grade" : "A",
            "score" : 11
        }, 
        {
            "date" : ISODate("2012-07-31T00:00:00.000Z"),
            "grade" : "A",
            "score" : 12
        }, 
        {
            "date" : ISODate("2011-12-29T00:00:00.000Z"),
            "grade" : "A",
            "score" : 12
        }
    ],
    "name" : "Dj Reynolds Pub And Restaurant",
    "restaurant_id" : "30191841"
}

I want to fetch list of all documents where zipcode is 10019 I'm following mongodb db tutorials and i've tried the following queries but nothing seems to work and i'm getting zero errors.

 db.restaurants.find({address:{zipcode:10019}});
    db.restaurants.find({"address.zipcode":10019})

1 Answer 1

3

zipcode is a string so your query should be

db.restaurants.find({ "address.zipcode": "10019" })

instead of

db.restaurants.find({ "address.zipcode": 10019 })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.