PHP code example of joorloohuis / yii2-mongodb

1. Go to this page and download the library: Download joorloohuis/yii2-mongodb library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

joorloohuis / yii2-mongodb example snippets



    'mongoclient' => [
        'class' => \joorloohuis\mongodb\components\MongoClient::class,
        'dsn' => 'mongodb://mongouser:mongopw@localhost:27017/database?args',
        // alternatively, provide separate parameters
        // 'host' => 'localhost',
        // 'port' => 27017,
        // 'user' => 'mongouser',
        // 'password' => 'mongopw',
        // 'db' => 'mongodatabase',
        // 'args' => 'args',
    ];

$collection = \Yii::$app->mongoclient->database->selectCollection('mycollection');
$cursor = $collection->aggregate([
    // aggregation pipeline parts go here
]);
$result = $cursor->toArray();
bash
php composer.phar