Node.js mongodb GeoJSON坐标必须是数组
需要搜索给定区域中的某些位置。下面是我在mongo中的测试数据示例:Node.js mongodb GeoJSON坐标必须是数组,node.js,mongodb,mongodb-query,geojson,Node.js,Mongodb,Mongodb Query,Geojson,需要搜索给定区域中的某些位置。下面是我在mongo中的测试数据示例: { "_id" : "insititution_NPqTrcysjKV", "phone" : "18080808088", "name" : "Insititution 1", "address" : "xxxxxxxxxxxxx", "city"
{
"_id" : "insititution_NPqTrcysjKV",
"phone" : "18080808088",
"name" : "Insititution 1",
"address" : "xxxxxxxxxxxxx",
"city" : "New York",
"location" : {
"type" : "Point",
"coordinates" : [
121.62764,
29.89805
]
},
"includeLessions" : [
"English"
]
}
我的mongodb中有一个这样的条目列表。下面是我在Robo3T中提出的问题:
db.Insititution.find(
{
location: {
$geoIntersects: {
$geometry: {
type: "Polygon" ,
coordinates: [
[ [ 121.33, 29.899 ], [ 121.33, 29.770 ], [ 121.67, 29.770 ], [ 121.67, 29.899 ], [ 121.33, 29.899 ] ]
]
}
}
}
}
)
它在robo3t中工作,但在我的项目中,我喜欢这样:
var where = {
location: {
$geoIntersects: {
$geometry: {
type: "Polygon",
coordinates: [
[longitudeMin, latitudeMin],
[longitudeMin, latitudeMax],
[longitudeMax, latitudeMax],
[longitudeMax, latitudeMin],
[longitudeMin, latitudeMin]
]
}
}
}
}
return promiseUtils.mongoNativeFindPromise(this.modelName, where);
// function in promiseUtils:
exports.mongoNativeFindPromise = async function (modelName, where, options) {
const db = await MongoClient.connect(uri);
try {
let collection = db.db(mongoDBSettings.database);
var cusor = await collection.collection(modelName).find(where, options);
return await cusor.toArray();
} catch (err) {
throw err;
} finally {
db.close();
}
};
这正是运行代码时“where”变量的变化:
但是mongo返回一个错误:GeoJSON坐标必须是一个数组
有人能帮忙吗?将您的多边形与此示例进行比较:它必须是
[[[longitudeMin,latitudeMin],[longitudeMin,latitudeMax],[longitudeMax,latitudeMax],[longitudeMax,latitudeMin],[longitudeMin,latitudeMin]]]
愚蠢的问题,请回答。将您的多边形与此示例进行比较:它必须是[[[longitudeMin,latitudeMin],[longitudeMin,latitudeMax],[longitudeMax,latitudeMax],[longitudeMax,latitudeMin],[longitudeMin,latitudeMin]].
愚蠢的问题,请回答