$ ear和$ within之间的MongoDB地理空间差异 [英] MongoDB geospatial difference between $near and $within

查看:51
本文介绍了$ ear和$ within之间的MongoDB地理空间差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$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); 

任何人都可以详细解释吗?

Can anyone explain in detail?

推荐答案

主要区别是

  • $near根据距点的距离进行排序; $geoWithin测试包含GeoJSON坐标的多边形或多面中的包含度,或包含2d坐标的一组形状中的包含度
  • $near从最近到最远返回文档,其他任何顺序都需要在内存中排序; $geoWithin可以与其他排序索引一起使用
  • $near需要地理空间索引; $geoWithin表现更好,但不需要它
  • 分片群集不支持
  • $near-您必须使用geonear命令或$geoNear聚合阶段
  • $near sorts based on distance from a point; $geoWithin tests for containment in a polygon or multipolygon with GeoJSON coordinates, or containment in one of a set of shapes for 2d coordinates
  • $near returns document from nearest to farthest and any other order requires in-memory sorting; $geoWithin can be used with other sort indexes
  • $near requires a geospatial index; $geoWithin performs better with one but does not require it
  • $near is not supported in sharded clusters - you have to use the geonear command or$geoNear aggregation stage instead

还要查看 $ near $ geoWithin .

这篇关于$ ear和$ within之间的MongoDB地理空间差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆