mongodb错误:{quot;$err";:“无效运算符:$geointen";,“代码”10068}

mongodb错误:{quot;$err";:“无效运算符:$geointen";,“代码”10068},mongodb,geojson,Mongodb,Geojson,当我尝试使用$GEOINTIN或$GEOSINTERSECTS查询几何图形时,出现了此错误 error: { "$err" : "invalid operator: $geoWithin", "code" : 10068 } 我尝试使用mongo v2.4.9(在LinuxMint上,我必须说我在更新到v2.4.9时遇到了问题,所以我手动将/usr/bin/中的二进制文件替换为来自的二进制文件,之后我运行mongod--升级) 下面是示例中的代码: s = db.shapes s.inse

当我尝试使用$GEOINTIN或$GEOSINTERSECTS查询几何图形时,出现了此错误

error: { "$err" : "invalid operator: $geoWithin", "code" : 10068 }
我尝试使用mongo v2.4.9(在LinuxMint上,我必须说我在更新到v2.4.9时遇到了问题,所以我手动将/usr/bin/中的二进制文件替换为来自的二进制文件,之后我运行mongod--升级)


下面是示例中的代码:

s = db.shapes

s.insert( {_id: "P1", shape: {type: "Point", coordinates: [2,2] } } )
s.insert( {_id: "P2", shape: {type: "Point", coordinates: [3,6] } } )
s.insert( {_id: "Poly1", shape: {type: "Polygon", coordinates: [[ [3,1], [1,2], [5,6], [9,2], [4,3], [3,1] ]] } })
s.insert( {_id: "LS1", shape: {type: "LineString", coordinates: [ [5,2], [7,3], [7,5], [9,4] ] } } )

s.ensureIndex({shape: "2dsphere"})

BOX = {type: "Polygon", coordinates: [[ [0,0], [3,0], [3,3], [0,3], [0,0] ]] }

s.find( {shape: {$geoIntersects: {$geometry: BOX}}}, {_id:1})
那么我有:

error: { "$err" : "invalid operator: $geoIntersects", "code" : 10068 }
error: { "$err" : "invalid operator: $geoWithin", "code" : 10068 }

那么我有:

error: { "$err" : "invalid operator: $geoIntersects", "code" : 10068 }
error: { "$err" : "invalid operator: $geoWithin", "code" : 10068 }


这在使用Mongo2.4.3的OSX上运行良好,我认为您的问题在于版本本身。检查Mongo是否抛出语法错误,因为“$geoIntersects”不存在,它已从$intersects更改为$geoIntersects,因此我将尝试使用以下命令运行相同的代码:

s.find( {shape: {$intersects: {$geometry: BOX}}}, {_id:1})
如果你有旧版本,它会工作$GeoInin也有同样的问题,Mongo没有发现。请使用检查您的版本

version()

我敢肯定这是安装问题,我在2.4.7中尝试了这段代码,它可以工作,在旧版本中没有,我不得不切换到$intersects

你能显示代码吗?是的,可能是版本问题。我运行了正确版本的mongo,但旧数据库可能仍然存在问题。我设法删除了我的数据库以重置所有内容,现在一切正常。您是否尝试运行$intersects?可能是数据库本身在所属的版本中,我不知道这个细节,很高兴知道。我没有尝试,也无法尝试,因为我删除了以前的所有数据库。。。但可能是这样的。知道这一点可能会很棒,我没有迁移数据库来测试它。很好,你修好了