Mongo相当于`select distinct(name)from employee where age ="25"`

Pra*_*eta 3 php mongodb

我需要帮助找到不同的值,但我还需要给出一个过滤条件.
我以这种方式管理了不同的东西:

$unique = $db->command(array("distinct" => "employee", "key" => "name"));  
Run Code Online (Sandbox Code Playgroud)

如何在此添加"where age ="25""子句?

谢谢你的帮助!

dcr*_*sta 9

distinct()在MongoDB shell中,该distinct命令都接受一个query参数,该参数用于过滤在确定不同键值时要考虑的记录集.在您的示例中,您可以:

db.employee.distinct("name", {"age": 25})
Run Code Online (Sandbox Code Playgroud)

在MongoDB shell中,或者:

$db->command(array("distinct" => "employee",
                   "key" => "name",
                   "query" => array("age" => 25)))
Run Code Online (Sandbox Code Playgroud)

用PHP.