Mongo在Node.js中:无法规范化查询:BadValue geoNear必须是顶级表达式

3
我这里有一个基于几何的查询,它被嵌套在$or内,并与 $and 操作符结合使用。Mongo一直抛出以下错误:
 MongoError: Can't canonicalize query: BadValue geoNear must be top-level expr

我正在使用原生的Mongo Node驱动程序版本1.4.3。我看到这里发布了一个类似的bug。

这是我构建查询的问题,还是应该向Mongo报告bug?

{
    "$or": [
        {
            "$and": [
                {
                    "startDate": {
                        "$gt": "2013-12-27T08:00:00.000Z"
                    }
                },
                {
                    "startDate": {
                        "$lt": "2013-02-08T08:00:00.000Z"
                    }
                },
                {
                    "loc": {
                        "$near": {
                            "$geometry": {
                                "type": "Point",
                                "coordinates": [
                                    123.3423,
                                    22.2131
                                ]
                            },
                            "$maxDistance": 4
                        }
                    }
                }
            ]
        },
        {
            "$and": [
                {
                    "startDate": {
                        "$gt": "2013-12-27T08:00:00.000Z"
                    }
                },
                {
                    "startDate": {
                        "$lt": "2013-02-08T08:00:00.000Z"
                    }
                }
            ]
        }
    ]
}
1个回答

7

我认为这是版本2.6中 $or 和地理查询的限制:

$or and GeoSpatial Queries

Changed in version 2.6.

$or supports geospatial clauses with the following exception for the near clause (near clause includes $nearSphere and $near). $or cannot contain a near clause with any other clause.

http://docs.mongodb.org/manual/reference/operator/query/or/

换句话说,这不是一个错误,而是一个功能。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接