Javascript 如何查找带有$geointen的文档,然后使用$geonear aggregate pipeline创建距离字段?
我在MongoDB收集了很多房子。我想首先找到给定位置($geointen)半径内的所有房屋,然后使用聚合管道$geonear在所有这些文档上创建一个距离字段。我怎么把这些链子连在一起Javascript 如何查找带有$geointen的文档,然后使用$geonear aggregate pipeline创建距离字段?,javascript,node.js,mongodb,mongoose,geospatial,Javascript,Node.js,Mongodb,Mongoose,Geospatial,我在MongoDB收集了很多房子。我想首先找到给定位置($geointen)半径内的所有房屋,然后使用聚合管道$geonear在所有这些文档上创建一个距离字段。我怎么把这些链子连在一起 Model.find({ location: { $geoWithin: { $centerSphere: [[lng, lat], radius]} } }) 我认为您根本不需要$geoinsin。$geoNear的near字段将包含与$geointen相同的坐标,是吗?$geoNear的maxDistanc
Model.find({
location: { $geoWithin: { $centerSphere: [[lng, lat], radius]} }
})
我认为您根本不需要
$geoinsin
。$geoNear
的near
字段将包含与$geointen
相同的坐标,是吗?$geoNear
的maxDistance
参数将用作半径,这是有意义的。非常感谢。
Model.aggregate([
{
//PLEASE NOTE: GeoNear must always be the first stage in the pipeline
$geoNear: {
near: {
type: 'Point',
coordinates: [lng, lat]
},
distanceField: 'distance',
distanceMultiplier: multiplier
}
}