I have used this query in shell. It worked fine. If I use it in php, it shows me an error
<?php
$m = new Mongo();
$db = $m->foo;
$collection = $db->base;
$query = array( "ro" => '/^a/' );
$cursor = $collection->find($query);
foreach ($cursor as $obj) {
echo $obj["ro"] . "<br/>";
}
I am not sure, will db.base.find({"ro": /^a/}).limit(10);
query work in php??
You need to use MongoRegex() ...
See docs here: http://php.net/manual/en/class.mongoregex.php
So the PHP code would be something like ...
$regex = new MongoRegex("/^a/");
$where = array('ro' => $regex);
$cursor = $collection->find($where);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With