yii\mongodb\Query::distinct PHP Method

distinct() public method

Returns a list of distinct values for the given column across a collection.
public distinct ( string $q, Connection $db = null ) : array
$q string column to use.
$db Connection the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used.
return array array of distinct values
    public function distinct($q, $db = null)
    {
        $collection = $this->getCollection($db);
        if ($this->where !== null) {
            $condition = $this->where;
        } else {
            $condition = [];
        }
        $result = $collection->distinct($q, $condition);
        if ($result === false) {
            return [];
        } else {
            return $result;
        }
    }