KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Not able to fetch inherited column values from mongodb. #1999

Open Srishti opened this topic on on Mar 27, 2021 - 1 comments

Srishti commented on Mar 27, 2021

I am trying to execute a simple program that can extract all the data stored in a MongoDB collection in tabular form. I am following the example programs provided on the koolreport website. They have clearly mentioned how to extract data from the nonobject column type. Which is working absolutely fine. But the program is not able to fetch the data from the inherited columns. It says "Fatal error: Uncaught Error: Object of class MongoDB\Model\BSONDocument could not be converted to the string".

I looked for solutions to this problem. I came across converting the MongoDB document into PHP so that data is presentable. But It kept showing the same error.

MongoDB collection (Employee) structure:

        {
         "name" : string,
         "tech" : {
            "name" : string
              }
         }

setup function:

            {
                $this->src('data')
                ->query(array (
                    "collection"=>"Employee",
                    "option"=>[
                        "projection"=>[
                            "name"=>1,
                            "tech.name"=>1
                        ]
                    ]
                ))
                ->pipe($this->dataStore('result'));
   
            }

Error: Fatal error: Uncaught Error: Object of class MongoDB\Model\BSONDocument could not be converted to string in C:\xampp\htdocs\demo\vendor\koolreport\core\src\widgets\koolphp\Table.tpl.php:138 Stack trace: #0 C:\xampp\htdocs\demo\vendor\koolreport\core\src\core\Widget.php(736): include() #1 C:\xampp\htdocs\demo\vendor\koolreport\core\src\widgets\koolphp\Table.php(431): koolreport\core\Widget->template('Table', Array) #2 C:\xampp\htdocs\demo\vendor\koolreport\core\src\core\Widget.php(676): koolreport\widgets\koolphp\Table->onRender() #3 C:\xampp\htdocs\demo\vendor\koolreport\core\src\core\Widget.php(764): koolreport\core\Widget->render() #4 C:\xampp\htdocs\demo\demoReport\demoReport.view.php(10): koolreport\core\Widget::create(Array) #5 C:\xampp\htdocs\demo\vendor\koolreport\core\src\KoolReport.php(502): include('C:\xampp\htdocs...') #6 C:\xampp\htdocs\demo\demoReport\index.php(8): koolreport\KoolReport->render() #7 {main} thrown in ### C:\xampp\htdocs\demo\vendor\koolreport\core\src\widgets\koolphp\Table.tpl.php on line 138

Sebastian Morales commented on Mar 29, 2021

Pls try the following code in the report's setup and let us know the result:

                $this->src('data')
                ->query(array (
                    "collection"=>"Employee",
                    "option"=>[
                        "projection"=>[
                            "name"=>1,
                            "tech.name"=>1
                        ]
                    ]
                ))
                ->pipe( new \koolreport\processes\Map(array(
                    "{value}" => function($row, $metaData, $index, $mapState) {
                        if ($index === 0) var_dump($row);
                    },
                )))
                ->pipe($this->dataStore('result'));

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

MongoDB