Rumah > Soal Jawab > teks badan
使用db.runCommand({geoNear : “collectionName” , near : [120.123456,30.654321], num : 10 })查询之前我需要准备什么样子的集合collection ?collection相应的字段和索引???
大家讲道理2017-05-02 09:19:53
Koleksi perlu menambah maklumat koordinat dalam format GeoJson, contohnya:
{ type: "Point", coordinates: [ 40, 5 ] }
Anda juga perlu membina indeks jenis 2dsphere, contohnya:
db.collection.createIndex( { <location field> : "2dsphere" } )
Untuk butiran lanjut, sila lihat dokumentasi mongodb:
https://docs.mongodb.org/manual/core/2dsphere/