PHP code example of koolreport / mongodb

1. Go to this page and download the library: Download koolreport/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/ */

    

koolreport / mongodb example snippets




class MyReport extends \koolreport\KoolReport
{
    public function settings()
    {
        return array(
            "dataSources"=>array(
                "mongo_purchase"=>array(
                    "class"=>'\koolreport\mongodb\MongoDataSource',
                    "connectionString"=>"mongo://johndoe:secret_password@localhost:65432",
                    "database"=>"dbpurchase"
                ),
            )
        );
    }
    public function setup()
    {
        $this->src('mongo_purchase')
        ->query(array(
            'collection' => 'cPurchases',
            'find' => ['age' => ['$gte' => '40']],
            'options' => [
                'skip' => 0,
                'limit' => 5,
                'projection' => [
                    '_id' => 0,
                    'name' => 1,
                    'age' => 1,
                ],    
            ],
        ))
        ->pipe(..)
        ->pipe(...)
        ...
        ->pipe($this->dataStore('mongo_purchases'));
    }
}