Property | Type | Description | |
---|---|---|---|
$db | the MongoDB connection. |
Method | Description | |
---|---|---|
__construct ( |
Constructor. | |
aggregate ( string $collectionName, array $pipelines, array $options = [] ) : array | Generates 'aggregate' command. | |
buildAndCondition ( string $operator, array $operands ) : array | Connects two or more conditions with the AND operator. | |
buildBetweenCondition ( string $operator, array $operands ) : array | Creates an Mongo condition, which emulates the BETWEEN operator. | |
buildCondition ( array $condition ) : array | Parses the condition specification and generates the corresponding Mongo condition. | |
buildHashCondition ( array $condition ) : array | Creates a condition based on column-value pairs. | |
buildInCondition ( string $operator, array $operands ) : array | Creates an Mongo condition with the IN operator. | |
buildLikeCondition ( string $operator, array $operands ) : array | Creates a Mongo condition, which emulates the LIKE operator. | |
buildNotCondition ( string $operator, array $operands ) : array | Composes NOT condition. | |
buildOrCondition ( string $operator, array $operands ) : array | Connects two or more conditions with the OR operator. | |
buildRegexCondition ( string $operator, array $operands ) : array | Creates a Mongo regular expression condition. | |
buildSelectFields ( array | string $fields ) : array | Normalizes fields list for the MongoDB select composition. | |
buildSimpleCondition ( string $operator, array $operands ) : string | Creates an Mongo condition like {$operator:{field:value}}. | |
buildSortFields ( array | string $fields ) : array | Normalizes fields list for the MongoDB sort composition. | |
count ( string $collectionName, array $condition = [], array $options = [] ) : array | Generates count command | |
createCollection ( string $collectionName, array $options = [] ) : array | Generates 'create collection' command. | |
createIndexes ( string | null $databaseName, string $collectionName, array[] $indexes ) : array | Generates create indexes command. | |
distinct ( string $collectionName, string $fieldName, array $condition = [], array $options = [] ) : array | Generates 'distinct' command. | |
dropCollection ( string $collectionName ) : array | Generates drop collection command. | |
dropDatabase ( ) : array | Generates drop database command. | |
dropIndexes ( string $collectionName, string $index ) : array | Generates drop indexes command. | |
explain ( string $collectionName, array $query ) : array | Generates 'explain' command. | |
findAndModify ( string $collectionName, array $condition = [], array $update = [], array $options = [] ) : array | Generates 'find and modify' command. | |
group ( string $collectionName, $keys, array $initial, MongoDB\BSON\Javascript | string $reduce, array $options = [] ) : array | Generates 'group' command. | |
listCollections ( array $condition = [], array $options = [] ) : array | Generates 'listCollections' command. | |
listDatabases ( array $condition = [], array $options = [] ) : array | Generates 'listDatabases' command. | |
listIndexes ( string $collectionName, array $options = [] ) : array | Generates list indexes command. | |
mapReduce ( string $collectionName, MongoDB\BSON\Javascript | string $map, MongoDB\BSON\Javascript | string $reduce, string | array $out, array $condition = [], array $options = [] ) : array | Generates 'map-reduce' command. |
Method | Description | |
---|---|---|
ensureMongoId ( mixed $rawId ) : array | MongoDB\BSON\ObjectID | Converts given value into [[ObjectID]] instance. | |
normalizeConditionKeyword ( string $key ) : string | Converts "\yii\db\*" quick condition keyword into actual Mongo condition keyword. |
Method | Description | |
---|---|---|
buildCompositeInCondition ( string $operator, array $columns, array $values ) : array | ||
generateIndexName ( array $columns ) : string | Generates index name for the given column orders. |
public __construct ( |
||
$connection | the database connection. | |
$config | array | name-value pairs that will be used to initialize the object properties |
public buildCondition ( array $condition ) : array | ||
$condition | array | the condition specification. Please refer to [[Query::where()]] on how to specify a condition. |
return | array | the generated Mongo condition |
public buildHashCondition ( array $condition ) : array | ||
$condition | array | the condition specification. |
return | array | the generated Mongo condition. |
public buildInCondition ( string $operator, array $operands ) : array | ||
$operator | string | the operator to use (e.g. `IN` or `NOT IN`) |
$operands | array | the first operand is the column name. If it is an array a composite IN condition will be generated. The second operand is an array of values that column value should be among. |
return | array | the generated Mongo condition. |
public buildSimpleCondition ( string $operator, array $operands ) : string | ||
$operator | string | the operator to use. Besides regular MongoDB operators, aliases like `>`, `<=`, and so on, can be used here. |
$operands | array | the first operand is the column name. The second operand is a single value that column value should be compared with. |
return | string | the generated Mongo condition. |
public createIndexes ( string | null $databaseName, string $collectionName, array[] $indexes ) : array | ||
$databaseName | string | null | database name. |
$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. |
return | array | command document. |
public distinct ( string $collectionName, string $fieldName, array $condition = [], array $options = [] ) : array | ||
$collectionName | string | collection name. |
$fieldName | string | target field name. |
$condition | array | filter condition |
$options | array | list of options in format: optionName => optionValue. |
return | array | command document. |
public dropCollection ( string $collectionName ) : array | ||
$collectionName | string | name of the collection to be dropped. |
return | array | command document. |
public dropDatabase ( ) : array | ||
return | array | command document. |
protected ensureMongoId ( mixed $rawId ) : array | MongoDB\BSON\ObjectID | ||
$rawId | mixed | raw id(s). |
return | array | MongoDB\BSON\ObjectID | normalized id(s). |
public findAndModify ( string $collectionName, array $condition = [], array $update = [], array $options = [] ) : array | ||
$collectionName | string | collection name |
$condition | array | filter condition |
$update | array | update criteria |
$options | array | list of options in format: optionName => optionValue. |
return | array | command document. |
public group ( string $collectionName, $keys, array $initial, MongoDB\BSON\Javascript | string $reduce, array $options = [] ) : array | ||
$collectionName | string | |
$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 [[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. |
return | array | command document. |
public mapReduce ( string $collectionName, MongoDB\BSON\Javascript | string $map, MongoDB\BSON\Javascript | string $reduce, string | array $out, array $condition = [], array $options = [] ) : 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. |
return | array | command document. |
protected normalizeConditionKeyword ( string $key ) : string | ||
$key | string | raw condition key. |
return | string | actual key. |