search

Home  >  Q&A  >  body text

mongodb geonear

使用db.runCommand({geoNear : “collectionName” , near : [120.123456,30.654321], num : 10 })查询之前我需要准备什么样子的集合collection ?collection相应的字段和索引???
黄舟黄舟2757 days ago560

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-05-02 09:19:53

    Collection needs to add coordinate information in GeoJson format, for example:

    { type: "Point", coordinates: [ 40, 5 ] }
    

    You also need to build a 2dsphere type index, for example:

    db.collection.createIndex( { <location field> : "2dsphere" } )
    

    For more details, please see mongodb’s documentation:
    https://docs.mongodb.org/manual/core/2dsphere/

    reply
    0
  • Cancelreply