MongoDB $near 和 $within 之间的地理空间差异
MongoDB geospatial difference between $near and $within
$near
和$within
有什么区别?
db.geodata.find({ "loc" : { "$within" : { "$center" : [ [ 12.91365 , 77.59395] , 4]}}}).limit(10);
db.geodata.find({ "loc" : { "$near" : [ 12.91365 , 77.59395] , "$maxDistance" : 4}}).limit(10);
谁能详细解释一下?
主要区别是
$near
根据与点的距离排序; $geoWithin
测试是否包含在具有 GeoJSON 坐标的多边形或多多边形中,或包含在二维坐标的一组形状之一中
$near
returns 文档从最近到最远,任何其他顺序都需要在内存中排序; $geoWithin
可与其他排序索引一起使用
$near
需要地理空间索引; $geoWithin
一个性能更好,但不需要它
分片集群不支持 $near
- 您必须使用 geonear
命令或 $geoNear
聚合阶段
另请查看 $near and $geoWithin 的文档。
$near
和$within
有什么区别?
db.geodata.find({ "loc" : { "$within" : { "$center" : [ [ 12.91365 , 77.59395] , 4]}}}).limit(10);
db.geodata.find({ "loc" : { "$near" : [ 12.91365 , 77.59395] , "$maxDistance" : 4}}).limit(10);
谁能详细解释一下?
主要区别是
$near
根据与点的距离排序;$geoWithin
测试是否包含在具有 GeoJSON 坐标的多边形或多多边形中,或包含在二维坐标的一组形状之一中$near
returns 文档从最近到最远,任何其他顺序都需要在内存中排序;$geoWithin
可与其他排序索引一起使用$near
需要地理空间索引;$geoWithin
一个性能更好,但不需要它
分片集群不支持 $near
- 您必须使用geonear
命令或$geoNear
聚合阶段
另请查看 $near and $geoWithin 的文档。