搜索

首页  >  问答  >  正文

如何mongoDB以数组中某元素的值的范围为条件查询?

{
  "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"
}

如何查询符合coord中纬度小于-95.754168的数据

漂亮男人漂亮男人2789 天前762

全部回复(1)我来回复

  • 世界只因有你

    世界只因有你2017-05-02 09:25:28

    这样写,数组的话下标从0开始。如果第一个值代表纬度的话

    db.collection.find({ "address.coord.0":{$lt:-95.754168} })

    回复
    0
  • 取消回复