mongodb geoNear vs附近 [英] mongodb geoNear vs near

查看:82
本文介绍了mongodb geoNear vs附近的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎mongodb为地理空间查询提供了两个类似的功能-$near$geoNear.根据mongo文档

It looks like mongodb offers two similar functions for geospatial queries - $near and $geoNear. According to the mongo docs

geoNear命令提供了$ near运算符的替代方法.在 除了$ near的功能外,geoNear还返回其他 诊断信息.

The geoNear command provides an alternative to the $near operator. In addition to the functionality of $near, geoNear returns additional diagnostic information.

看起来geoNear提供了near功能的超集.例如,near似乎仅返回最接近的100个文档,而geoNear允许您指定最大值.是否有理由使用near而不是geoNear?一个比另一个更有效吗?

It looks like geoNear provides a superset of the near functionality. For example, near seems to only return the closest 100 documents, whereas geoNear lets you specify a maximum. Is there a reason to use near instead of geoNear? Is one more efficient than the other?

推荐答案

两者的效率均应相同.

Efficiency should be identical for either.

geoNear的主要限制是,作为命令,它可以返回最大文档大小的结果集,因为所有匹配的文档都在单个结果文档中返回.它还要求在每个结果文档中添加一个距离字段,根据您的使用情况,该字段可能会或可能不会成为问题.

geoNear's major limitation is that as a command it can return a result set up to the maximum document size as all of the matched documents are returned in a single result document. It also requires that a distance field be added to each result document which may or may not be an issue depending on your usage.

$near是查询运算符,因此结果可以大于单个文档(它们仍在单个响应中返回,但不是单个文档).您还可以通过查询的limit()设置最大文档数.

$near is a query operator so the results can be larger than a single document (they are still returned in a single response but not a single document). You can also set the maximum number of documents via the query's limit().

我倾向于建议用户坚持使用$near,除非他们需要geonear命令中的diagnostics(例如,距离或位置匹配).

I tend to recommend that users stick with the $near unless they need the diagnostics (e.g., distance, or location matched) from the geonear command.

这篇关于mongodb geoNear vs附近的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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