我有一个在 MongoDB 中运行良好的基本地理空间查询。似乎应用 $not 来获得补集应该很容易......但它对我不起作用。这是简单的用户错误吗?或者 MongoDB 在概念上不能处理这个查询吗?我在中找不到任何此类限制文档 http://www.mongodb.org/display/DOCS/Geospatial+Indexing.
工作查询(正确找到距中心 10 英里以内的 2 个城市):
db.customers.find({ "location" : { $within : { $center : [[-117.15,32.72],0.15] } } })
尝试补全查询(所需结果是不在 10 英里范围内的 1 个城市):
db.customers.find({ "location" : { $not : { $within : { $center : [[-117.15,32.72],0.15] } } } })
error: {
"$err" : "missing geo field (location) in : {location: { $not: { $within: { $center: [ [ -117.15, 32.72 ], 0.15 ] } } } }",
"code" : 13042
}
对于任何想要复制/粘贴查询以查看错误的人,这里有一些示例数据:
db.customers.ensureIndex( { "location" : "2d" } )
db.customers.save({"city":"La Mesa","state":"CA","location":[ -117.02,32.76 ]})
db.customers.save({"city":"Chula Vista","state":"CA","location":[ -117.08,32.63 ]})
db.customers.save({"city":"Mexico City","state":"Mexico","location":[-99.133244,19.4326]})
(我正在使用 MongoDB 1.8.2,以防万一。)