PHP 클래스 yii\mongodb\Query

Query provides a set of methods to facilitate the specification of "find" command. These methods can be chained together. For example, ~~~ $query = new Query; compose the query $query->select(['name', 'status']) ->from('customer') ->limit(10); execute the query $rows = $query->all(); ~~~
부터: 2.0
저자: Paul Klimov ([email protected])
상속: extends yii\base\Component, implements yii\db\QueryInterface, use trait yii\db\QueryTrait
파일 보기 프로젝트 열기: yiisoft/yii2-mongodb 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$from the collection to be selected from. If string considered as the name of the collection inside the default database. If array - first element considered as the name of the database, second - as name of collection inside that database
$options cursor options in format: optionKey => optionValue
$select the fields of the results to return. For example: ['name', 'group_id'], ['name' => true, '_id' => false]. Unless directly excluded, the "_id" field is always returned. If not set, it means selecting all columns.

공개 메소드들

메소드 설명
addOptions ( array $options ) Adds additional cursor options.
all ( Connection $db = null ) : array Executes the query and returns all results as an array.
andFilterCompare ( string $name, string $value, string $defaultOperator = '=' ) Helper method for easy querying on values containing some common operators.
average ( string $q, Connection $db = null ) : integer Returns the average of the specified column values.
batch ( integer $batchSize = 100, Connection $db = null ) : BatchQueryResult Starts a batch query.
buildCursor ( Connection $db = null ) : MongoDB\Driver\Cursor Builds the Mongo cursor for this query.
column ( Connection $db = null ) : array Executes the query and returns the first column of the result.
count ( string $q = '*', Connection $db = null ) : integer Returns the number of records.
distinct ( string $q, Connection $db = null ) : array Returns a list of distinct values for the given column across a collection.
each ( integer $batchSize = 100, Connection $db = null ) : BatchQueryResult Starts a batch query and retrieves data row by row.
exists ( Connection $db = null ) : boolean Returns a value indicating whether the query result contains any row of data.
from ( $collection ) Sets the collection to be selected from.
getCollection ( Connection $db = null ) : Collection Returns the Mongo collection for this query.
max ( string $q, Connection $db = null ) : integer Returns the maximum of the specified column values.
min ( string $q, Connection $db = null ) : integer Returns the minimum of the specified column values.
modify ( array $update, array $options = [], Connection $db = null ) : array | null Performs 'findAndModify' query and returns a single row of result.
one ( Connection $db = null ) : array | boolean Executes the query and returns a single row of result.
options ( array $options ) Sets the cursor options.
populate ( array $rows ) : array Converts the raw query results into the format as specified by this query.
scalar ( Connection $db = null ) : string | null | false Returns the query result as a scalar value.
select ( array $fields ) Sets the list of fields of the results to return.
sum ( string $q, Connection $db = null ) : integer Returns the sum of the specified column values.

보호된 메소드들

메소드 설명
aggregate ( string $column, string $operator, Connection $db ) : integer Performs the aggregation for the given column.
fetchRows ( MongoDB\Driver\Cursor $cursor, boolean $all = true, string | callable $indexBy = null ) : array | boolean Fetches rows from the given Mongo cursor.
fetchRowsInternal ( MongoDB\Driver\Cursor $cursor, boolean $all ) : array | boolean

비공개 메소드들

메소드 설명
composeCondition ( ) : array Composes condition from raw [[where]] value.

메소드 상세

addOptions() 공개 메소드

Adds additional cursor options.
또한 보기: options()
public addOptions ( array $options )
$options array cursor options in format: optionName => optionValue

aggregate() 보호된 메소드

Performs the aggregation for the given column.
protected aggregate ( string $column, string $operator, Connection $db ) : integer
$column string column name.
$operator string aggregation operator.
$db Connection the database connection used to execute the query.
리턴 integer aggregation result.

all() 공개 메소드

Executes the query and returns all results as an array.
public all ( Connection $db = null ) : array
$db Connection the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used.
리턴 array the query results. If the query results in nothing, an empty array will be returned.

andFilterCompare() 공개 메소드

The comparison operator is intelligently determined based on the first few characters in the given value and internally translated to a MongoDB operator. In particular, it recognizes the following operators if they appear as the leading characters in the given value: <: the column must be less than the given value ($lt). >: the column must be greater than the given value ($gt). <=: the column must be less than or equal to the given value ($lte). >=: the column must be greater than or equal to the given value ($gte). <>: the column must not be the same as the given value ($ne). Note that when $partialMatch is true, this would mean the value must not be a substring of the column. =: the column must be equal to the given value ($eq). none of the above: use the $defaultOperator Note that when the value is empty, no comparison expression will be added to the search condition.
또한 보기: yii\mongodb\Collection::buildCondition()
부터: 2.0.5
public andFilterCompare ( string $name, string $value, string $defaultOperator = '=' )
$name string column name
$value string column value
$defaultOperator string Defaults to =, performing an exact match. For example: use 'LIKE' or 'REGEX' for partial cq regex matching

average() 공개 메소드

Returns the average of the specified column values.
public average ( string $q, Connection $db = null ) : integer
$q string the column name. Make sure you properly quote column names in the expression.
$db Connection the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used.
리턴 integer the average of the specified column values.

batch() 공개 메소드

A batch query supports fetching data in batches, which can keep the memory usage under a limit. This method will return a BatchQueryResult object which implements the Iterator interface and can be traversed to retrieve the data in batches. For example, php $query = (new Query)->from('user'); foreach ($query->batch() as $rows) { $rows is an array of 10 or fewer rows from user collection }
부터: 2.1
public batch ( integer $batchSize = 100, Connection $db = null ) : BatchQueryResult
$batchSize integer the number of records to be fetched in each batch.
$db Connection the MongoDB connection. If not set, the "mongodb" application component will be used.
리턴 BatchQueryResult the batch query result. It implements the `Iterator` interface and can be traversed to retrieve the data in batches.

buildCursor() 공개 메소드

Builds the Mongo cursor for this query.
public buildCursor ( Connection $db = null ) : MongoDB\Driver\Cursor
$db Connection the database connection used to execute the query.
리턴 MongoDB\Driver\Cursor mongo cursor instance.

column() 공개 메소드

Column _id will be automatically excluded from select fields, if [[select]] is not empty and _id is not selected explicitly.
부터: 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.
리턴 array the first column of the query result. An empty array is returned if the query results in nothing.

count() 공개 메소드

Returns the number of records.
public count ( string $q = '*', Connection $db = null ) : integer
$q string kept to match [[QueryInterface]], its value is ignored.
$db Connection the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used.
리턴 integer number of records

distinct() 공개 메소드

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.
리턴 array array of distinct values

each() 공개 메소드

This method is similar to Query::batch except that in each iteration of the result, only one row of data is returned. For example, php $query = (new Query)->from('user'); foreach ($query->each() as $row) { }
부터: 2.1
public each ( integer $batchSize = 100, Connection $db = null ) : BatchQueryResult
$batchSize integer the number of records to be fetched in each batch.
$db Connection the MongoDB connection. If not set, the "mongodb" application component will be used.
리턴 BatchQueryResult the batch query result. It implements the `Iterator` interface and can be traversed to retrieve the data in batches.

exists() 공개 메소드

Returns a value indicating whether the query result contains any row of data.
public exists ( Connection $db = null ) : boolean
$db Connection the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used.
리턴 boolean whether the query result contains any row of data.

fetchRows() 보호된 메소드

Fetches rows from the given Mongo cursor.
protected fetchRows ( MongoDB\Driver\Cursor $cursor, boolean $all = true, string | callable $indexBy = null ) : array | boolean
$cursor MongoDB\Driver\Cursor Mongo cursor instance to fetch data from.
$all boolean whether to fetch all rows or only first one.
$indexBy string | callable the column name or PHP callback, by which the query results should be indexed by.
리턴 array | boolean result.

fetchRowsInternal() 보호된 메소드

또한 보기: Query::fetchRows()
protected fetchRowsInternal ( MongoDB\Driver\Cursor $cursor, boolean $all ) : array | boolean
$cursor MongoDB\Driver\Cursor Mongo cursor instance to fetch data from.
$all boolean whether to fetch all rows or only first one.
리턴 array | boolean result.

from() 공개 메소드

Sets the collection to be selected from.
public from ( $collection )

getCollection() 공개 메소드

Returns the Mongo collection for this query.
public getCollection ( Connection $db = null ) : Collection
$db Connection Mongo connection.
리턴 Collection collection instance.

max() 공개 메소드

Returns the maximum of the specified column values.
public max ( string $q, Connection $db = null ) : integer
$q string the column name. Make sure you properly quote column names in the expression.
$db Connection the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used.
리턴 integer the maximum of the specified column values.

min() 공개 메소드

Returns the minimum of the specified column values.
public min ( string $q, Connection $db = null ) : integer
$q string the column name. Make sure you properly quote column names in the expression.
$db Connection the database connection used to generate the SQL statement. If this parameter is not given, the `db` application component will be used.
리턴 integer the minimum of the specified column values.

modify() 공개 메소드

Performs 'findAndModify' query and returns a single row of result.
public modify ( array $update, array $options = [], Connection $db = null ) : array | null
$update array update criteria
$options array list of options in format: optionName => optionValue.
$db Connection the Mongo connection used to execute the query.
리턴 array | null the original document, or the modified document when $options['new'] is set.

one() 공개 메소드

Executes the query and returns a single row of result.
public one ( Connection $db = null ) : array | boolean
$db Connection the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used.
리턴 array | boolean the first row (in terms of an array) of the query result. False is returned if the query results in nothing.

options() 공개 메소드

Sets the cursor options.
또한 보기: addOptions()
public options ( array $options )
$options array cursor options in format: optionName => optionValue

populate() 공개 메소드

This method is internally used to convert the data fetched from database into the format as required by this query.
public populate ( array $rows ) : array
$rows array the raw query result from database
리턴 array the converted query result

scalar() 공개 메소드

The value returned will be the first column in the first row of the query results. Column _id will be automatically excluded from select fields, if [[select]] is not empty and _id is not selected explicitly.
부터: 2.1.2
public scalar ( Connection $db = null ) : string | null | false
$db Connection the MongoDB connection used to generate the query. If this parameter is not given, the `mongodb` application component will be used.
리턴 string | null | false the value of the first column in the first row of the query result. `false` is returned if the query result is empty.

select() 공개 메소드

Sets the list of fields of the results to return.
public select ( array $fields )
$fields array fields of the results to return.

sum() 공개 메소드

Returns the sum of the specified column values.
public sum ( string $q, Connection $db = null ) : integer
$q string the column name. Make sure you properly quote column names in the expression.
$db Connection the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used.
리턴 integer the sum of the specified column values

프로퍼티 상세

$from 공개적으로 프로퍼티

the collection to be selected from. If string considered as the name of the collection inside the default database. If array - first element considered as the name of the database, second - as name of collection inside that database
또한 보기: from()
public $from

$options 공개적으로 프로퍼티

cursor options in format: optionKey => optionValue
또한 보기: MongoDB\Driver\Cursor::addOption()
또한 보기: options()
public $options

$select 공개적으로 프로퍼티

the fields of the results to return. For example: ['name', 'group_id'], ['name' => true, '_id' => false]. Unless directly excluded, the "_id" field is always returned. If not set, it means selecting all columns.
또한 보기: select()
public $select