使用$ not的MongoDB地理空间查询

mda*_*man 8 geospatial mongodb

我有一个基本的地理空间查询在MongoDB中运行良好.似乎应该很容易应用$来获得补充...但它不适合我.这是简单的用户错误吗?或者MongoDB可以在概念上不处理这个查询?我在文档中找不到任何此类限制.

工作查询(正确找到中心10英里范围内的2个城市):

db.customers.find({ "location" : { $within : { $center : [[-117.15,32.72],0.15] } } })
Run Code Online (Sandbox Code Playgroud)

尝试补充查询(期望的结果是不在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
}
Run Code Online (Sandbox Code Playgroud)

对于想要复制/粘贴查询以查看错误的任何人,这里有一些示例数据:

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]})
Run Code Online (Sandbox Code Playgroud)

(我正在使用MongoDB 1.8.2以防万一.)

mne*_*syn 5

我认为这是不可能的.据我所知,位置查询将为您提供一个特殊的游标,只能使用位置查询作为参数(如$within).

v.2.0.1给出了更具描述性的错误消息: error: { "$err" : "geo field only has 1 element", "code" : 13068 }

索引的问题在于,通常,否定是EVIL.当你转动它们时,大多数索引都不能很好地应对,所以即使你的查询有效,它也可能不合适,因为它可能不得不进行表扫描.

我对此并不完全确定,给新闻组的消息可能是一个好主意.

  • 是的,发布到新闻组有帮助.其他人有类似的要求.支持$或$ all可能更有用(更少EVIL),但它们也不受支持.这里要求改进:https://jira.mongodb.org/browse/SERVER-3984 (3认同)