带有pymongo聚合的$ geoWithin $ center抛出错误

时间:2014-02-08 05:10:42

标签: mongodb pymongo

这是我的聚合:

query = [
    {'$match' : { 'location' : { 
        '$geoWithin': {'$center' : [ [lng,lat], distance ] }} }}
]
dumps(DB.venue.aggregate(query))

然而它抛出:

OperationFailure: command SON([('aggregate', u'venue'), ('pipeline', 
[{'$match': {'location': {'$geoWithin': {'$center': [[u'23.729310', u'37.983716'], 
0.0023544184586407157]}}}}])]) failed: exception: Malformed geo query: { $geoWithin: 
{ $center: [ [ "23.729310", "37.983716" ], 0.002354418458640716 ] } }

我还尝试使用$within代替$geoWithin$centerSphere代替$center,但不是。{通常,find()查询适用于内部和中心(docs)。

它是一个bug还是pymongo不支持?因为java驱动程序适用于$geoWithin$centerSphere

1 个答案:

答案 0 :(得分:4)

首先,正确的查询是:

{'$match' : {'location' : {'$geoWithin': {'$centerSphere': [[lng,lat], distance] }} }},

然而,我传递的lng和lat不是浮点数而是unicode字符,因此抛出了错误。