【发布时间】:2017-06-03 13:57:36
【问题描述】:
我正在尝试使用 Eve 通过 geoNear 聚合运算符查询 MongoDB 数据库,但在使用聚合变量时我得到以下信息:
'OperationFailure: geoNear command failed: { ok: 0.0, errmsg: "'near' field must be point", code: 17304, codeName: "Location17304" }'
聚合端点在settings.py中设置如下:
geoAggr = {'datasource':{
'source':'geo',
'aggregation': {
'pipeline': [
{'$geoNear':{
'near': {'type':'Point', 'coordinates':['$lon', '$lat']},
'distanceField':'distance',
'maxDistance':'$maxDistance',
'spherical': True,
'query':{
'recentAnalyses.KeywordCombinationAll /300 v1':{
'$exists': True
}
}
}}
]
}
}}
使用 POSTMAN 和 GET 请求对xxx.xxx.xxx.xxx:5000/geoAggr?aggregate={"$lon":"10.5","$lat":"10.5","$maxDistance":100000} 进行查询。
如果$lon 和$lat 被硬编码值替换,那么聚合器就可以完美运行,所以这似乎与变量放入聚合器的方式有关。我的第一个想法是这些数字可能会被解释为字符串,但 $maxDistance 参数可以按预期工作。
为什么它不能与变量一起使用?
【问题讨论】:
-
$在 MongoDB 中保留。能不能把变量名改一下试试? -
变量在到达 mongo 之前实际上已被 Eve 替换(我已经尝试过更改它们,这是基于 Eve 文档python-eve.org/features.html#mongodb-aggregation-framework 中的示例)。我现在已经找到了解决方案,不过感谢您的建议