gpt4 book ai didi

node.js - Node.js 中的 Mongo : Can't canonicalize query: BadValue geoNear must be top-level expr

转载 作者:可可西里 更新时间:2023-11-01 09:31:22 25 4
gpt4 key购买 nike

我这里有一个基于几何的查询,它嵌套在 $or 中并与 $and 运算符组合。

Mongo 不断抛出以下错误:

 MongoError: Can't canonicalize query: BadValue geoNear must be top-level expr

我正在使用 native Mongo Node 驱动程序与 1.4.3。我看到一个类似的错误发布 here .

这是我构建查询错误的情况,还是我应该向 Mongo 提交错误?

{
"$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"
}
}
]
}
]
}

最佳答案

我认为这是 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/

换句话说,不是错误而是功能

关于node.js - Node.js 中的 Mongo : Can't canonicalize query: BadValue geoNear must be top-level expr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23615408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com