MongoDb按数组长度查找对象

时间:2014-06-23 20:36:08

标签: mongodb

我的数据库中有一个像这样的对象

{
  "_id" : ObjectId("53a88d81a00456db9687fd1b"),
  "id" : NumberLong(381341),
  "version" : "14",
  "changeset" : "8658593",
  "uid" : "12919",
  "user" : "Cerritus",
  "timestamp" : "2011-07-07T15:47:09Z",
  "poly" : {
    "type" : "LineString",
    "coordinates" : [[8.5904504, 49.8634605], [8.5904517, 49.8634134], [8.5905602, 49.8624448], [8.5906698, 49.8616734], [8.5908094, 49.86097], [8.5908963, 49.8603052], [8.5909131, 49.8602373], [8.5909636, 49.8598595], [8.5910442, 49.859171]]
  },
  "highway" : "unclassified",
  "name" : "Flughafenstraße"
}

为什么这个查询什么都不返回?

{'poly.coordinates.length': {$eq:7}}

1 个答案:

答案 0 :(得分:1)

正确的查询是

{"poly.coordinates": { $size: 7 }}