我在shell中使用过这个查询.它工作正常.如果我在php中使用它,它会显示一个错误
<?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/>";
}
Run Code Online (Sandbox Code Playgroud)
我不确定,会db.base.find({"ro": /^a/}).limit(10);
在php中查询工作吗?
你需要使用MongoRegex()......
请参阅此处的文档:http://php.net/manual/en/class.mongoregex.php
那么PHP代码就像......
$regex = new MongoRegex("/^a/");
$where = array('ro' => $regex);
$cursor = $collection->find($where);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5777 次 |
最近记录: |