简体   繁体   中英

MongoDB: GeoJSON object type index, Can't extract geo keys

I have made many the below GeoJSON Point objects in MongoDB Compass as per the docs

{
    "_id": {
        "$oid": "5e86d275a3d7fd05e4f022a8"
    },
    "location": {
        "type": "point",
        "coordinates": ["-110.85458435", "39.68476146"]
    },
    "website": "carbonmedicalservice.com",
    "address": "125 S Main St",
    "state": "UT",
    "zip": "84526",
    "name": "Carbon Medical"
}

I want to be able te search the collection to return all records within an reactangle, I believe I need to add a Geospatial Indexe to the location but I get the error shown below...

在此处输入图像描述

This is how I entered the data:

在此处输入图像描述

In a GeoJSON type, coordinates should be float/double not string.

Also, the type should be Point , not point in your case. So, the GeoJSON in your case should be:

{
  "type": "Point",
  "coordinates": [-110.85458435, 39.68476146]
}

instead of

{
  "type": "point",
  "coordinates": ["-110.85458435", "39.68476146"]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM