Skip to content

Error Connecting to MongoDB #14

Description

@A-Pradeep

Hi , im trying to connect the koolReport to the MongoDB but i'm facing some error

Fatal error: Uncaught Error: Class 'MongoDB\Driver\Manager' not found in C:\xampp\htdocs\caas\dash\koolreport\packages\mongodb\vendor\mongodb\mongodb\src\Client.php:81 Stack trace: #0 C:\xampp\htdocs\caas\dash\koolreport\packages\mongodb\MongoDataSource.php(59): MongoDB\Client->__construct('mongodb://127.0...') #1 C:\xampp\htdocs\caas\dash\koolreport\core\DataSource.php(22): koolreport\mongodb\MongoDataSource->onInit() #2 C:\xampp\htdocs\caas\dash\koolreport\KoolReport.php(215): koolreport\core\DataSource->__construct(Array, Object(SalesByCustomer)) #3 C:\xampp\htdocs\caas\dash\SalesByCustomer.php(26): koolreport\KoolReport->src('mongo_purchase') #4 C:\xampp\htdocs\caas\dash\koolreport\KoolReport.php(39): SalesByCustomer->setup() #5 C:\xampp\htdocs\caas\dash\index.php(5): koolreport\KoolReport->__construct() #6 {main} thrown in C:\xampp\htdocs\caas\dash\koolreport\packages\mongodb\vendor\mongodb\mongodb\src\Client.php on line 81

And i'm new to this so i need some guidance to connecting the koolReport to the MongoDB ,
The Code as follows


<?php
// index.php: Just a bootstrap file
require_once "SalesByCustomer.php";

$salesByCustomer = new SalesByCustomer;
$salesByCustomer->run()->render();
<?php
// SalesByCustomer.php - Report setup file
require_once "koolreport/autoload.php";
use \koolreport\processes\Group;
use \koolreport\processes\Sort;
use \koolreport\processes\Limit;
use \koolreport\mongodb\MongoDataSource;

class SalesByCustomer extends \koolreport\KoolReport
{
    public function settings()
    {
        return array(
            "dataSources"=>array(
                "mongo_purchase"=>array(
                    "class"=>'\koolreport\mongodb\MongoDataSource',
                    "connectionString"=>"mongodb://127.0.0.1:27017",
                    "database"=>"formioapp"
                ),
            )
        );
    }

    public function setup()
    {
        $this->src('mongo_purchase')
        ->query(array("collections"=>"forms"))
        ->pipe($this->dataStore('mongo_purchases'));
    }
}
<?php 
// SalesByCustomer.view.php - Handle the report view
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\BarChart;
?>

<div class="text-center">
    <h1>Sales Report</h1>
    <h4>This report shows top 10 sales by customer</h4>
</div>
<hr/>

<?php
BarChart::create(array(
    "dataStore"=>$this->dataStore('sales_by_customer'),
    "width"=>"100%",
    "height"=>"500px",
    "columns"=>array(
        "customerName"=>array(
            "label"=>"Customer"
        ),
        "dollar_sales"=>array(
            "type"=>"number",
            "label"=>"Amount",
            "prefix"=>"$",
        )
    ),
    "options"=>array(
        "title"=>"Sales By Customer"
    )
));
?>

<?php
Table::create(array(
    "dataStore"=>$this->dataStore('sales_by_customer'),
        "columns"=>array(
            "customerName"=>array(
                "label"=>"Customer"
            ),
            "dollar_sales"=>array(
                "type"=>"number",
                "label"=>"Amount",
                "prefix"=>"$",
            )
        ),
    "cssClass"=>array(
        "table"=>"table table-hover table-bordered"
    )
));
?>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions