简体   繁体   English

PHP Mongo查询未返回预期结果

[英]PHP Mongo query not returning expected results

I'm using the latest php mongo driver along with the latest mongodb 2.0. 我正在使用最新的php mongo驱动程序以及最新的mongodb 2.0。 I'm trying to run a base query of host=x return the results then refine the search with other terms. 我正在尝试运行host = x的基本查询,以返回结果,然后使用其他术语优化搜索。

It's not returning any valid results. 它没有返回任何有效的结果。

I was thinking something like this, but its obviously not working: 我在想这样的事情,但显然不起作用:

$basefilter = array('host' => new MongoRegex("/1.1.1.1|2.2.2.2/i"));
$filter = array('host' => new MongoRegex("/2.2.2.2/i"));
$basereturn = $collection->find($basefilter);
$initreturn = $basereturn->find($filter);
$return = $initreturn->sort(array('date' => -1))->limit($limit)->skip($skip);

I want to just be able to refine my search. 我只想优化搜索范围。 How can this be done? 如何才能做到这一点?

You can't run a find over a cursor. 您不能在游标上运行查找。 find only works over collections. 查找仅对集合有效。 I suspect the above fatals out. 我怀疑上面的致命伤了。 You can map/reduce into a collection and run find on it. 您可以映射/归约到集合中并在其上运行查找。

您可能应该对您的正则表达式进行替换,因为该点是正则表达式中的运算符,因此应该是:

$basefilter = array('host' => new MongoRegex("/(1\.1\.1\.1)|(2\.2\.2\.2)/i"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM