【发布时间】:2020-05-31 15:04:08
【问题描述】:
query = {
"location" : {
"$near" : {
"$geometry": {
"type": "Point" ,
"coordinates": [18.55,73.78]
}
}
}
}
}
planner returned error: unable to find index for $geoNear query
at Connection.<anonymous> (D:\Projects\api\node_modules\mongodb-core\lib\connection\pool.js:443:61)
at Connection.emit (events.js:198:13)
at Connection.EventEmitter.emit (domain.js:466:23)
at processMessage (D:\Projects\api\node_modules\mongodb-core\lib\connection\connection.js:364:10)
at Socket.<anonymous> (D:\Projects\api\node_modules\mongodb-core\lib\connection\connection.js:533:15)
at Socket.emit (events.js:198:13)
at Socket.EventEmitter.emit (domain.js:466:23)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
ok: 0,
为此,我在以下链接中指定的位置字段上创建了 2dsphere
https://docs.mongodb.com/manual/core/2dsphere/
db.collectionName.createIndex( { location : "2dsphere" } )
如果我做错了什么,请帮助我理解。
【问题讨论】:
-
尝试将
$near更改为$nearSphere并在$geometry旁边添加$minDistance: 0和$maxDistance: yourmaxdistance如果它仍然不起作用 -
感谢@AshwynHorton 的信息。我也尝试过使用$nearSphere ......但仍然遇到同样的错误。
-
酷酷,如果对您有帮助,请告诉我...
-
是的.. 尝试了这个 $nearSphere.. 但没有工作.. 仍然得到同样的错误..
标签: node.js mongodb mongoose geolocation geometry