带有过滤器的 mongodb geoNear 命令 [英] mongodb geoNear command with filter

查看:87
本文介绍了带有过滤器的 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 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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