简体   繁体   中英

mongoDB geospatial

I have this format of data in my collection:

{
    "_id" : ObjectId("53563136d91216a097fc4e12"),
    "type" : "Feature",
    "geometry" : {
        "type" : "LineString",
        "coordinates" : [
            [13468472.06, 1625377.26],
            [13468446.27, 1625383.95], 
            [13468425.24, 1625398.28], 
            [13468396.58, 1625419.29]
        ]
    }
}

When perform this query:

db.foobar.find({ 
    "geometry":{ 
        "$near": { 
            "$geometry": { 
                "type": "Point",
                "coordinates" : [13468472, 1625377] 
            }
        }
    }
})

Why don't I get the results? and how do I perform the query when I want to know what specific points belong to that LineString?

Unfortunately, as of now, you cannot perform the queries of '$near' operator on anything other than 'Point' type geometries. This is why you are not getting the results.

If you wish to see a demonstration of $near, you can try creating a collection of points - index it - and then run the query.

One useful video link i found to see $near in action is this . The video is not a very recent one but is still good.

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