带有过滤器的 mongodb geoNear 命令

编程入门 行业动态 更新时间:2024-10-09 21:23:19
本文介绍了带有过滤器的 mongodb geoNear 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在使用 mongodb 的 geoNear 命令和附加查询来过滤结果时遇到了一些问题.以下查询是使用rockmongo进行的.

I've come across some issues when using mongodb's geoNear command with an additional query to filter the results. The following queries are made with rockmongo.

在我的集合poi"中,文档有profiles",它是一个包含 objectid 的数组.搜索它们时:

In my collection "poi", documents have "profiles", which is an array containing objectids. When searching for them :

{ geoNear : "poi", near : [19,47], query : {profiles : ObjectId("511f360901c610e813000004")} }

我没有得到任何结果.

Response from server: { "ns": "local.poi", "near": "1100010010100011101101101111001010100011101101101111", "results": [ ], "stats": { "time": NumberInt(2), "btreelocs": NumberInt(0), "nscanned": NumberInt(510), "objectsLoaded": NumberInt(510), "avgDistance": 0, "maxDistance": 0 }, "ok": 1 }

但是,如果没有查询,或者即使使用简单的 {profiles : ObjectId("511f360901c610e813000004")} 查询,我也得到了预期的结果.

However, without the query, or even with a simple {profiles : ObjectId("511f360901c610e813000004")} query I get the expected results.

另一个问题是当我有大约一半的文档带有name"x",另一半带有y"时,查询

Another issue is when I have approximately half of the documents with "name" "x", and the other half with "y", the query

{ geoNear : "poi", near : [47,19.5], query : {"$and" : [{name : { "$in" : [/.*y.*/i]}}]} }

没有结果,当简单的 {"$and" : [{name : { "$in" : [/.y./i]}}]} 给出它们时.这个示例查询实际上可以非常简单,尽管结果没有区别,这更像是我在项目中的实际查询.

gives no results, when the simple {"$and" : [{name : { "$in" : [/.y./i]}}]} gives them. This example query in fact can be much simple, though there's no difference regarding the results, and this is more like my actual queries in the project.

当我用 PHP 尝试这些时,无论传递了多少附加查询,我都会得到结果,因此每个文档都按距离排序.

When I try these with PHP, I get results regardless of the additional query being passed, so every document sorted by distance.

请帮我看看是不是我做错了.

Please help me find out if I'm doing it wrong.

推荐答案

好的,问题出在 PHP 驱动程序上.我发现它在mongo shell中可以工作,所以我切换回1.3.1,现在它可以工作了!

Okay, the problem was with the PHP driver. I discovered that it works in the mongo shell, so I switched back to 1.3.1, and now it works!

更多推荐

带有过滤器的 mongodb geoNear 命令

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

发布评论

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

>www.elefans.com

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