yii\mongodb\Query::column PHP Method

column() public method

Column _id will be automatically excluded from select fields, if [[select]] is not empty and _id is not selected explicitly.
Since: 2.1.2
public column ( Connection $db = null ) : array
$db Connection the MongoDB connection used to generate the query. If this parameter is not given, the `mongodb` application component will be used.
return array the first column of the query result. An empty array is returned if the query results in nothing.
    public function column($db = null)
    {
        $originSelect = (array) $this->select;
        if (!isset($originSelect['_id']) && array_search('_id', $originSelect, true) === false) {
            $this->select['_id'] = false;
        }
        if (is_string($this->indexBy) && $originSelect && count($originSelect) === 1) {
            $this->select[] = $this->indexBy;
        }
        $cursor = $this->buildCursor($db);
        $rows = $this->fetchRows($cursor, true);
        if (empty($rows)) {
            return [];
        }
        $results = [];
        foreach ($rows as $row) {
            $value = reset($row);
            if ($this->indexBy === null) {
                $results[] = $value;
            } else {
                if ($this->indexBy instanceof \Closure) {
                    $results[call_user_func($this->indexBy, $row)] = $value;
                } else {
                    $results[$row[$this->indexBy]] = $value;
                }
            }
        }
        return $results;
    }