$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
和 $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坐标的多边形或复合多边形中,或者在2d坐标的一组形状中包含。$near
返回从最近到最远的文档,任何其他顺序都需要内存排序;$geoWithin
可以与其他排序索引一起使用。$near
需要地理空间索引; $geoWithin
在使用地理空间索引时性能更好,但不需要它。$near
不支持分片集群 - 必须使用geonear
命令或$geoNear
聚合阶段。