gpt4 book ai didi

mongodb - $near 需要 geojson 点,给定 geojson 点

转载 作者:可可西里 更新时间:2023-11-01 09:45:16 26 4
gpt4 key购买 nike

我有包含如下地理字段的文档。

"geo" : {
"type" : "Point",
"coordinates" : [
37.44609999,
-121.88355687
]
},

我已经创建了一个空间索引,证明如下。

db.collection.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "db.collection",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"geo.coordinates" : "2dsphere"
},
"ns" : "db.collection",
"name" : "geo.coordinates_2dsphere"
}
]

但是,当我执行以下查询时(MongoDB 手册中逐字记录)。

db.collection.find( { 'geo.coordinates': { $near: 
{ $geometry :
{ type : "Point",
coordinates: [ 37.44609999, -121.88355687 ] } },
$maxDistance: 1000
} } )

我收到以下错误。

error: {
"$err" : "$near requires geojson point, given { type: \"Point\", coordinates: [ 37.44609999, -121.88355687 ] }",
"code" : 16681
}

谁能告诉我为什么?

最佳答案

这样翻转点:

“地理”:{ “类型”:“点”, “坐标”:[ -121.88355687, 37.44609999 ]},

否则,请检查您的坐标以查看它们是否真实: http://geojsonlint.com/

关于mongodb - $near 需要 geojson 点,给定 geojson 点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19085840/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com