gpt4 book ai didi

mongoDB 地理空间查询 $geoWithin 出现错误 'Loop is not closed'

转载 作者:行者123 更新时间:2023-12-05 08:55:00 24 4
gpt4 key购买 nike

我是 mongodb 地理空间查询的新手,我尝试在具有如下代码的多边形内搜索点:

db.properties.find({
location:{
$geoWithin : {
$geometry : {
type:"Polygon",
coordinates: [[
[104.9172382, 11.57934524],
[104.9146632, 11.5724502],
[104.92753788, 11.57976566]
]]
}
}
}
})

我的数据表如下所示: enter image description here

我想得到所有点都在多边形内的结果。但我真的不知道

这个错误总是弹出

|____/ Mongo Server error (MongoQueryException): Query failed with error code 2 and error message 'Loop is not closed: [ [ 104.9172382, 11.57934524 ], [ 104.9146632, 11.5724502 ], [ 104.92753788, 11.57976566 ] ]' on server

感谢任何想法!

最佳答案

我找到了答案,我们需要开始坐标和结束坐标是相同的值。

db.properties.find({
location:{
$geoWithin : {
$geometry : {
type:"Polygon",
coordinates:[
[
[ 104.9212999921292 , 11.575955591122819 ] , // start loop
[ 104.92129194550216 , 11.575198826419006 ] ,
[ 104.92298978380859 , 11.575238241297862 ] ,
[ 104.92291736416519 , 11.576023910057827 ] ,
[ 104.9212999921292 , 11.575955591122819 ] // close loop
]
]
}
}
}
})

关于mongoDB 地理空间查询 $geoWithin 出现错误 'Loop is not closed',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47665844/

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