-
Notifications
You must be signed in to change notification settings - Fork 58
Commands and Aggregation queries
Dmitriy Verkhoumov edited this page Mar 27, 2018
·
12 revisions
Execute command in MongoDB. A complete list of commands can be found in official documentation MongoDB.
Syntax:
function command(array $command = []): array
Arguments:
-
command
— array with a list of commands, required.
Return: array with the results of the command execution.
Example of use:
$result = $this->mongo_db->command([
'serverStatus' => TRUE,
'rangeDeleter' => TRUE
]);
Execute aggregation in MongoDB. A complete list of aggregation operators can be found in [official documentation] (https://docs.mongodb.com/manual/reference/operator/aggregation/) MongoDB.
Syntax:
function aggregate(string $collection = '', array $pipeline = [], array $options = []): array
NOTE: if you are using MongoDB version 3.6 or later, be sure to specify the cursors
option in the $options
.
Arguments:
-
collection
— collection name, required. -
pipeline
— aggregation request, required. -
options
— aggregation options. A complete list of aggregation operators can be found in official documentation (options
) MongoDB.
Return: array with aggregation results.
Example of use:
$result = $this->mongo_db->aggregate(
'stocks',
[
[
'$project' => [
'cusip' => 1,
'date' => 1,
'price' => 1,
'_id' => 0
]
]
],
[
'allowDiskUse' => TRUE
]
);
Dear user, at the moment I'm writing a detailed WIKI and translating it into English.