简体   繁体   中英

PHP Mongo query not returning expected results

I'm using the latest php mongo driver along with the latest mongodb 2.0. I'm trying to run a base query of host=x return the results then refine the search with other terms.

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"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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