计算给定地理多边形内的$平均值

calculating $avg value within a given geo polygon

我正在尝试计算给定多边形内的值:

实际上我正在使用这个管道:

    'aggregation': {
        'pipeline': [
            { "$match" : { "location" : "$loc" } },
            { "$group": { "_id": 'Average', "AvgField": { "$avg": "$myavgvalue" }  , "count": {"$sum": 1} } },
        ]
    }

但 $match 似乎忽略了地理空间索引。

知道我该怎么做吗?

此致 哈拉尔德

您需要使用 ?aggregate={"$loc": ...} 查询语法,因此解析器知道它必须调用聚合引擎而不是标准查询解析器。这个例子直接来自 documentation:

$ curl -i http://example.com/posts?aggregate={"$value": 2}

此外,请确保已将正确的地理索引添加到集合中。 Eve 不会自动为您执行此操作,除非您通过设置 mongo_indexes.

明确选择这样做