嗨,我正在练习mongodb而且我遇到了问题。我是以下几套文件。
{
"_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"
}
我想获取zipcode为10019的所有文档的列表 我正在关注mongodb数据库教程,我已经尝试了以下查询,但似乎没有任何工作,我得到零错误。
db.restaurants.find({address:{zipcode:10019}});
db.restaurants.find({"address.zipcode":10019})
答案 0 :(得分:3)
zipcode
是一个字符串,因此您的查询应为
db.restaurants.find({ "address.zipcode": "10019" })
而不是
db.restaurants.find({ "address.zipcode": 10019 })