我在 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/>";
}
我不确定,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);
关于php - 我需要在 mongo php 中使用类似查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5009854/