I need help with finding distinct values but I also need to give a filter condition.
I have managed the distinct in this fashion :
$unique = $db->command(array("distinct" => "employee", "key" => "name"));
How do I add the "where age = "25" " clause to this?
Thanks for you help!
distinct()
in the MongoDB shell, and the distinct
command both take a query
argument which is used to filter the set of records to consider when determining distinct key values. In your example, you could do:
db.employee.distinct("name", {"age": 25})
in the MongoDB shell, or:
$db->command(array("distinct" => "employee",
"key" => "name",
"query" => array("age" => 25)))
in PHP.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.