Mongo equivalent of SQL's SELECT DISTINCT?

前端 未结 2 1560
一向
一向 2021-01-20 07:00

As per the title, what would be the PHP Mongo equivalent of something like this in SQL:

SELECT DISTINCT(field) FROM table WHERE someCondition = 1
         


        
2条回答
  •  庸人自扰
    2021-01-20 07:31

    If you need to add a where clause, use the following syntax:

    $ages = $db->command(array(
        "distinct" => "people", 
        "key" => "age",
        "query" => array("someField" => "someValue")));
    

提交回复
热议问题