MongoDB 使用 geoWithin 查询时出错
MongoDB query with geoWithin works wrong
我有一个与 mongoDB
有关的问题。假设我们有一个集合 points
,其中有一个点:
db.points.insert(
{
name: 'point1',
location: {
type: "Point",
coordinates: [-11, -1]
}
}
);
我用 geoWithin
编写了以下查询:
let foundPoints = db.points.find(
{
location: {
$geoWithin: {
$geometry: {
type: 'Polygon',
coordinates: [[[-15, -5], [-5, 5], [-5, -5], [-15, -5]]]
}
}
}
}
);
const answer = foundPoints.map(doc => doc.name);
让我们看看点[-11, -1]
在给定三角形的边上,但是查询没有找到这个点。我想知道我做错了什么。你能帮忙吗?
提前致谢。
点 (-11,-1) 仅在 (-15,-5)-(-5,5) 的直线上,如果它们是平面坐标。
如果那些是球体上的经度和纬度,则点 (-11,-1) 位于该三角形之外。
在https://geojson.io处绘制点和三角形,该点实际上在三角形西北约100米处。
我有一个与 mongoDB
有关的问题。假设我们有一个集合 points
,其中有一个点:
db.points.insert(
{
name: 'point1',
location: {
type: "Point",
coordinates: [-11, -1]
}
}
);
我用 geoWithin
编写了以下查询:
let foundPoints = db.points.find(
{
location: {
$geoWithin: {
$geometry: {
type: 'Polygon',
coordinates: [[[-15, -5], [-5, 5], [-5, -5], [-15, -5]]]
}
}
}
}
);
const answer = foundPoints.map(doc => doc.name);
让我们看看点[-11, -1]
在给定三角形的边上,但是查询没有找到这个点。我想知道我做错了什么。你能帮忙吗?
提前致谢。
点 (-11,-1) 仅在 (-15,-5)-(-5,5) 的直线上,如果它们是平面坐标。
如果那些是球体上的经度和纬度,则点 (-11,-1) 位于该三角形之外。
在https://geojson.io处绘制点和三角形,该点实际上在三角形西北约100米处。