mongodb geoNear vs附近

编程入门 行业动态 更新时间:2024-10-17 17:18:57
本文介绍了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附近

本文发布于:2023-11-22 13:37:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:mongodb   geoNear

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!