Normal regular-Expression query for MongoDB is faster in console mode. For example customer name start with "Ale": this following query is very faster.
db.labels.find({ "customer.name": { $regex: /^Ale/i } },{"label.name":1})
but once i try this same kind of query in PHP its take huge time to load:
$page =int($_request["p"])
$limit = 20;
$skip = ($page - 1) * $limit;
$next = ($page + 1);
$prev = ($page - 1);
$name = "Ale";
$regexObj = new MongoRegex("/^".$name."/i");
$where = array("customer.name" => $regexObj);
$sort = array('customer.id' => -1);
$result = $collection->find($where)->skip($skip)->limit($limit)->sort($sort);
When i remove $where condition from the query it runs very faster.
But ofcorse i need the $where
.
Any suggestion or any solution will be appreciated!