PHP 클래스 yii\mongodb\Command

A command object is usually created by calling [[Connection::createCommand()]] or [[Database::createCommand()]]. The statement it represents can be set via the [[document]] property. To execute a non-query command, such as 'listIndexes', 'count', 'distinct' and so on, call Command::execute. For example: php $result = Yii::$app->mongodb->createCommand(['listIndexes' => 'some_collection'])->execute(); To execute a 'find' command, which return cursor, call Command::query. For example: php $cursor = Yii::$app->mongodb->createCommand(['projection' => ['name' => true]])->query('some_collection'); To execute batch (bulk) operations, call Command::executeBatch. For example: php Yii::$app->mongodb->createCommand() ->addInsert(['name' => 'new']) ->addUpdate(['name' => 'existing'], ['name' => 'updated']) ->addDelete(['name' => 'old']) ->executeBatch('some_collection');
부터: 2.1
저자: Paul Klimov ([email protected])
상속: extends yii\base\Object
파일 보기 프로젝트 열기: yiisoft/yii2-mongodb

공개 프로퍼티들

프로퍼티 타입 설명
$databaseName name of the database that this command is associated with.
$db the MongoDB connection that this command is associated with.
$document command document contents.

공개 메소드들

메소드 설명
addDelete ( array $condition, array $options = [] ) Adds the delete operation to the batch command.
addInsert ( array $document ) Adds the insert operation to the batch command.
addUpdate ( array $condition, array $document, array $options = [] ) Adds the update operation to the batch command.
aggregate ( string $collectionName, array $pipelines, array $options = [] ) : array Performs aggregation using MongoDB Aggregation Framework.
batchInsert ( string $collectionName, array[] $documents, array $options = [] ) : array | false Inserts batch of new documents into collection.
count ( string $collectionName, array $condition = [], array $options = [] ) : integer Counts records in specified collection.
createCollection ( string $collectionName, array $options = [] ) : boolean Creates new collection in database associated with this command.s
createIndexes ( string $collectionName, array[] $indexes ) : boolean Creates indexes in the collection.
delete ( string $collectionName, array $condition, array $options = [] ) : MongoDB\Driver\WriteResult Removes documents from the collection.
distinct ( string $collectionName, string $fieldName, array $condition = [], array $options = [] ) : array Returns a list of distinct values for the given column across a collection.
dropCollection ( string $collectionName ) : boolean Drops specified collection.
dropDatabase ( ) : boolean Drops database associated with this command.
dropIndexes ( string $collectionName, string $indexes ) : array Drops collection indexes by name.
execute ( ) : MongoDB\Driver\Cursor Executes this command.
executeBatch ( string $collectionName, array $options = [] ) : array Execute commands batch (bulk).
explain ( string $collectionName, array $query ) : array Return an explanation of the query, often useful for optimization and debugging.
find ( string $collectionName, array $condition, array $options = [] ) : MongoDB\Driver\Cursor Performs find query.
findAndModify ( $collectionName, array $condition = [], array $update = [], array $options = [] ) : array | null Updates a document and returns it.
getReadConcern ( ) : MongoDB\Driver\ReadConcern | string Retuns read concern for this command.
getReadPreference ( ) : MongoDB\Driver\ReadPreference Returns read preference for this command.
getWriteConcern ( ) : MongoDB\Driver\WriteConcern | null Returns write concern for this command.
group ( string $collectionName, mixed $keys, array $initial, MongoDB\BSON\Javascript | string $reduce, array $options = [] ) : array Performs aggregation using MongoDB "group" command.
insert ( string $collectionName, array $document, array $options = [] ) : MongoDB\BSON\ObjectID | boolean Inserts new document into collection.
listCollections ( array $condition = [], array $options = [] ) : array Returns the list of available collections.
listDatabases ( array $condition = [], array $options = [] ) : array Returns the list of available databases.
listIndexes ( string $collectionName, array $options = [] ) : array Returns information about current collection indexes.
mapReduce ( string $collectionName, MongoDB\BSON\Javascript | string $map, MongoDB\BSON\Javascript | string $reduce, string | array $out, array $condition = [], array $options = [] ) : string | array Performs MongoDB "map-reduce" command.
query ( string $collectionName, array $options = [] ) : MongoDB\Driver\Cursor Executes this command as a mongo query
setReadConcern ( MongoDB\Driver\ReadConcern | string $readConcern ) Sets read concern for this command.
setReadPreference ( MongoDB\Driver\ReadPreference | integer | string | null $readPreference ) Sets read preference for this command.
setWriteConcern ( MongoDB\Driver\WriteConcern | integer | string | null $writeConcern ) Sets write concern for this command.
update ( string $collectionName, array $condition, array $document, array $options = [] ) : MongoDB\Driver\WriteResult Update existing documents in the collection.

보호된 메소드들

메소드 설명
beginProfile ( string $token, string $category ) Marks the beginning of a code block for profiling.
endProfile ( string $token, string $category ) Marks the end of a code block for profiling.
log ( array | string $namespace, array $data, string $category ) : string | false Logs the command data if logging is enabled at [[db]].

메소드 상세

addDelete() 공개 메소드

Adds the delete operation to the batch command.
또한 보기: executeBatch()
public addDelete ( array $condition, array $options = [] )
$condition array filter condition.
$options array delete options.

addInsert() 공개 메소드

Adds the insert operation to the batch command.
또한 보기: executeBatch()
public addInsert ( array $document )
$document array document to be inserted

addUpdate() 공개 메소드

Adds the update operation to the batch command.
또한 보기: executeBatch()
public addUpdate ( array $condition, array $document, array $options = [] )
$condition array filter condition
$document array data to be updated
$options array update options.

aggregate() 공개 메소드

Performs aggregation using MongoDB Aggregation Framework.
public aggregate ( string $collectionName, array $pipelines, array $options = [] ) : array
$collectionName string collection name
$pipelines array list of pipeline operators.
$options array optional parameters.
리턴 array aggregation result.

batchInsert() 공개 메소드

Inserts batch of new documents into collection.
public batchInsert ( string $collectionName, array[] $documents, array $options = [] ) : array | false
$collectionName string collection name
$documents array[] documents list
$options array list of options in format: optionName => optionValue.
리턴 array | false list of inserted IDs, `false` on failure.

beginProfile() 보호된 메소드

Marks the beginning of a code block for profiling.
또한 보기: endProfile()
protected beginProfile ( string $token, string $category )
$token string token for the code block
$category string the category of this log message

count() 공개 메소드

Counts records in specified collection.
public count ( string $collectionName, array $condition = [], array $options = [] ) : integer
$collectionName string collection name
$condition array filter condition
$options array list of options in format: optionName => optionValue.
리턴 integer records count

createCollection() 공개 메소드

Creates new collection in database associated with this command.s
public createCollection ( string $collectionName, array $options = [] ) : boolean
$collectionName string collection name
$options array collection options in format: "name" => "value"
리턴 boolean whether operation was successful.

createIndexes() 공개 메소드

Creates indexes in the collection.
public createIndexes ( string $collectionName, array[] $indexes ) : boolean
$collectionName string collection name.
$indexes array[] indexes specification. Each specification should be an array in format: optionName => value The main options are: - keys: array, column names with sort order, to be indexed. This option is mandatory. - unique: bool, whether to create unique index. - name: string, the name of the index, if not set it will be generated automatically. - background: bool, whether to bind index in the background. - sparse: bool, whether index should reference only documents with the specified field. See [[https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/#options-for-all-index-types]] for the full list of options.
리턴 boolean whether operation was successful.

delete() 공개 메소드

Removes documents from the collection.
public delete ( string $collectionName, array $condition, array $options = [] ) : MongoDB\Driver\WriteResult
$collectionName string collection name.
$condition array filter condition.
$options array delete options.
리턴 MongoDB\Driver\WriteResult write result.

distinct() 공개 메소드

Returns a list of distinct values for the given column across a collection.
public distinct ( string $collectionName, string $fieldName, array $condition = [], array $options = [] ) : array
$collectionName string collection name.
$fieldName string field name to use.
$condition array query parameters.
$options array list of options in format: optionName => optionValue.
리턴 array array of distinct values, or "false" on failure.

dropCollection() 공개 메소드

Drops specified collection.
public dropCollection ( string $collectionName ) : boolean
$collectionName string name of the collection to be dropped.
리턴 boolean whether operation was successful.

dropDatabase() 공개 메소드

Drops database associated with this command.
public dropDatabase ( ) : boolean
리턴 boolean whether operation was successful.

dropIndexes() 공개 메소드

Drops collection indexes by name.
public dropIndexes ( string $collectionName, string $indexes ) : array
$collectionName string collection name.
$indexes string wildcard for name of the indexes to be dropped.
리턴 array result data.

endProfile() 보호된 메소드

Marks the end of a code block for profiling.
또한 보기: beginProfile()
protected endProfile ( string $token, string $category )
$token string token for the code block
$category string the category of this log message

execute() 공개 메소드

Executes this command.
public execute ( ) : MongoDB\Driver\Cursor
리턴 MongoDB\Driver\Cursor result cursor.

executeBatch() 공개 메소드

Execute commands batch (bulk).
public executeBatch ( string $collectionName, array $options = [] ) : array
$collectionName string collection name.
$options array batch options.
리턴 array array of 2 elements: - 'insertedIds' - contains inserted IDs. - 'result' - [[\MongoDB\Driver\WriteResult]] instance.

explain() 공개 메소드

Return an explanation of the query, often useful for optimization and debugging.
public explain ( string $collectionName, array $query ) : array
$collectionName string collection name
$query array query document.
리턴 array explanation of the query.

find() 공개 메소드

Performs find query.
public find ( string $collectionName, array $condition, array $options = [] ) : MongoDB\Driver\Cursor
$collectionName string collection name
$condition array filter condition
$options array query options.
리턴 MongoDB\Driver\Cursor result cursor.

findAndModify() 공개 메소드

Updates a document and returns it.
public findAndModify ( $collectionName, array $condition = [], array $update = [], array $options = [] ) : array | null
$collectionName
$condition array query condition
$update array update criteria
$options array list of options in format: optionName => optionValue.
리턴 array | null the original document, or the modified document when $options['new'] is set.

getReadConcern() 공개 메소드

Retuns read concern for this command.
public getReadConcern ( ) : MongoDB\Driver\ReadConcern | string
리턴 MongoDB\Driver\ReadConcern | string read concern to be used in this command.

getReadPreference() 공개 메소드

Returns read preference for this command.
public getReadPreference ( ) : MongoDB\Driver\ReadPreference
리턴 MongoDB\Driver\ReadPreference read preference.

getWriteConcern() 공개 메소드

Returns write concern for this command.
public getWriteConcern ( ) : MongoDB\Driver\WriteConcern | null
리턴 MongoDB\Driver\WriteConcern | null write concern to be used in this command.

group() 공개 메소드

Performs aggregation using MongoDB "group" command.
public group ( string $collectionName, mixed $keys, array $initial, MongoDB\BSON\Javascript | string $reduce, array $options = [] ) : array
$collectionName string collection name.
$keys mixed fields to group by. If an array or non-code object is passed, it will be the key used to group results. If instance of [[\MongoDB\BSON\Javascript]] passed, it will be treated as a function that returns the key to group by.
$initial array Initial value of the aggregation counter object.
$reduce MongoDB\BSON\Javascript | string function that takes two arguments (the current document and the aggregation to this point) and does the aggregation. Argument will be automatically cast to [[\MongoDB\BSON\Javascript]].
$options array optional parameters to the group command. Valid options include: - condition - criteria for including a document in the aggregation. - finalize - function called once per unique key that takes the final output of the reduce function.
리턴 array the result of the aggregation.

insert() 공개 메소드

Inserts new document into collection.
public insert ( string $collectionName, array $document, array $options = [] ) : MongoDB\BSON\ObjectID | boolean
$collectionName string collection name
$document array document content
$options array list of options in format: optionName => optionValue.
리턴 MongoDB\BSON\ObjectID | boolean inserted record ID, `false` - on failure.

listCollections() 공개 메소드

Returns the list of available collections.
public listCollections ( array $condition = [], array $options = [] ) : array
$condition array filter condition.
$options array options list.
리턴 array collections information.

listDatabases() 공개 메소드

Returns the list of available databases.
public listDatabases ( array $condition = [], array $options = [] ) : array
$condition array filter condition.
$options array options list.
리턴 array database information

listIndexes() 공개 메소드

Returns information about current collection indexes.
public listIndexes ( string $collectionName, array $options = [] ) : array
$collectionName string collection name
$options array list of options in format: optionName => optionValue.
리턴 array list of indexes info.

log() 보호된 메소드

Logs the command data if logging is enabled at [[db]].
protected log ( array | string $namespace, array $data, string $category ) : string | false
$namespace array | string command namespace.
$data array command data.
$category string log category
리턴 string | false log token, `false` if log is not enabled.

mapReduce() 공개 메소드

Performs MongoDB "map-reduce" command.
public mapReduce ( string $collectionName, MongoDB\BSON\Javascript | string $map, MongoDB\BSON\Javascript | string $reduce, string | array $out, array $condition = [], array $options = [] ) : string | array
$collectionName string collection name.
$map MongoDB\BSON\Javascript | string function, which emits map data from collection. Argument will be automatically cast to [[\MongoDB\BSON\Javascript]].
$reduce MongoDB\BSON\Javascript | string function that takes two arguments (the map key and the map values) and does the aggregation. Argument will be automatically cast to [[\MongoDB\BSON\Javascript]].
$out string | array output collection name. It could be a string for simple output ('outputCollection'), or an array for parametrized output (['merge' => 'outputCollection']). You can pass ['inline' => true] to fetch the result at once without temporary collection usage.
$condition array filter condition for including a document in the aggregation.
$options array additional optional parameters to the mapReduce command. Valid options include: - sort: array, key to sort the input documents. The sort key must be in an existing index for this collection. - limit: int, the maximum number of documents to return in the collection. - finalize: \MongoDB\BSON\Javascript|string, function, which follows the reduce method and modifies the output. - scope: array, specifies global variables that are accessible in the map, reduce and finalize functions. - jsMode: bool, specifies whether to convert intermediate data into BSON format between the execution of the map and reduce functions. - verbose: bool, specifies whether to include the timing information in the result information.
리턴 string | array the map reduce output collection name or output results.

query() 공개 메소드

Executes this command as a mongo query
public query ( string $collectionName, array $options = [] ) : MongoDB\Driver\Cursor
$collectionName string collection name
$options array query options.
리턴 MongoDB\Driver\Cursor result cursor.

setReadConcern() 공개 메소드

Sets read concern for this command.
public setReadConcern ( MongoDB\Driver\ReadConcern | string $readConcern )
$readConcern MongoDB\Driver\ReadConcern | string read concern, it can be an instance of [[ReadConcern]] or scalar level value, for example: 'local'.

setReadPreference() 공개 메소드

Sets read preference for this command.
public setReadPreference ( MongoDB\Driver\ReadPreference | integer | string | null $readPreference )
$readPreference MongoDB\Driver\ReadPreference | integer | string | null read reference, it can be specified as instance of [[ReadPreference]] or scalar mode value, for example: `ReadPreference::RP_PRIMARY`.

setWriteConcern() 공개 메소드

Sets write concern for this command.
public setWriteConcern ( MongoDB\Driver\WriteConcern | integer | string | null $writeConcern )
$writeConcern MongoDB\Driver\WriteConcern | integer | string | null write concern, it can be an instance of [[WriteConcern]] or its scalar mode value, for example: `majority`.

update() 공개 메소드

Update existing documents in the collection.
public update ( string $collectionName, array $condition, array $document, array $options = [] ) : MongoDB\Driver\WriteResult
$collectionName string collection name
$condition array filter condition
$document array data to be updated.
$options array update options.
리턴 MongoDB\Driver\WriteResult write result.

프로퍼티 상세

$databaseName 공개적으로 프로퍼티

name of the database that this command is associated with.
public $databaseName

$db 공개적으로 프로퍼티

the MongoDB connection that this command is associated with.
public $db

$document 공개적으로 프로퍼티

command document contents.
public $document