diff --git a/extensions/mongo/Database.php b/extensions/mongo/Database.php index c6ecc74..2ff5abb 100644 --- a/extensions/mongo/Database.php +++ b/extensions/mongo/Database.php @@ -75,4 +75,15 @@ class Database extends Object { return $this->mongoDb->createCollection($name, $options); } + + /** + * Executes Mongo command. + * @param array $command command specification. + * @param array $options options in format: "name" => "value" + * @return array database response. + */ + public function execute($command, $options = []) + { + return $this->mongoDb->command($command, $options); + } } \ No newline at end of file diff --git a/tests/unit/extensions/mongo/DatabaseTest.php b/tests/unit/extensions/mongo/DatabaseTest.php index ec0bf2d..dbe05c0 100644 --- a/tests/unit/extensions/mongo/DatabaseTest.php +++ b/tests/unit/extensions/mongo/DatabaseTest.php @@ -31,4 +31,16 @@ class DatabaseTest extends MongoTestCase $collectionRefreshed = $database->getCollection('customer', true); $this->assertFalse($collection === $collectionRefreshed); } + + public function testCommand() + { + $database = $connection = $this->getConnection()->getDatabase(); + + $result = $database->execute([ + 'distinct' => 'customer', + 'key' => 'name' + ]); + $this->assertTrue(array_key_exists('ok', $result)); + $this->assertTrue(array_key_exists('values', $result)); + } } \ No newline at end of file