mongo中有一个集合,有文档,每个文档都包含数组坐标,例如[59.952673, 30.293132]。为了搜索这些坐标,我使用了 2dsphere 索引。我正在使用查询进行搜索:
db.objects.find({coordinates: {$nearSphere: {$geometry: {
type: "Point",
coordinates: [59.952673, 30.293132]},
$maxDistance: 100
}}}).limit(5)
对于指定的坐标,一切正常。例如,这里是Google 搜索的结果,这些是现有坐标。但同时,现有坐标 [64.89633499999999, 141.724606] 也会报错:
db.objects.find({coordinates: {$nearSphere: {$geometry: {
type: "Point",
coordinates: [64.89633499999999, 141.724606]},
$maxDistance: 100
}}}).limit(5)
[2022-09-30 15:43:49] Query failed with error code 2 and error message 'invalid point in geo near query $geometry argument: { type: "Point", coordinates: [ 64.89633499999999, 141.724606 ] } longitude/latitude is out of bounds, lng: 64.8963 lat: 141.725'
我究竟做错了什么?为什么坐标在一种情况下是正确的,而在另一种情况下却超出范围?