Uncaught Error: Class “MongoDBClient” not found in

I am creating custom divi module and want to fetch data from mongodb database and display it accordingly.

Here is full log of the error:

Fatal error: Uncaught Error: Class "MongoDBClient" not found in C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-contentpluginstestincludesmodulesExamsExams.php:53 Stack trace: #0 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-contentpluginstestincludesmodulesExamsExams.php(37): Exams->get_mongodb_data() #1 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-contentthemesDiviincludesbuilderclass-et-builder-element.php(3433): Exams->render(Array, '', 'test_exams', '', '', '', '', '') #2 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-includesshortcodes.php(433): ET_Builder_Element->_render(Array, '', 'test_exams') #3 [internal function]: do_shortcode_tag(Array) #4 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-includesshortcodes.php(273): preg_replace_callback('/\[(\[?)(et_pb_...', 'do_shortcode_ta...', '[et_pb_text _bu...') #5 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-contentthemesDiviincludesbuildermain-structure-elements.php(3784): do_shortcode('[et_pb_text _bu...') #6 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-contentthemesDiviincludesbuilderclass-et-builder-element.php(3433): ET_Builder_Column->render(Array, '[et_pb_text _bu...', 'et_pb_column', '', '', '', '', '') #7 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-includesshortcodes.php(433): ET_Builder_Element->_render(Array, '[et_pb_text _bu...', 'et_pb_column') #8 [internal function]: do_shortcode_tag(Array) #9 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-includesshortcodes.php(273): preg_replace_callback('/\[(\[?)(et_pb_...', 'do_shortcode_ta...', '[et_pb_column t...') #10 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-contentthemesDiviincludesbuildermain-structure-elements.php(2274): do_shortcode('[et_pb_column t...') #11 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-contentthemesDiviincludesbuilderclass-et-builder-element.php(3433): ET_Builder_Row->render(Array, '[et_pb_column t...', 'et_pb_row', '', '', '', '', '') #12 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-includesshortcodes.php(433): ET_Builder_Element->_render(Array, '[et_pb_column t...', 'et_pb_row') #13 [internal function]: do_shortcode_tag(Array) #14 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-includesshortcodes.php(273): preg_replace_callback('/\[(\[?)(et_pb_...', 'do_shortcode_ta...', '[et_pb_row colu...') #15 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-contentthemesDiviincludesbuildermain-structure-elements.php(1606): do_shortcode('[et_pb_row colu...') #16 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-contentthemesDiviincludesbuilderclass-et-builder-element.php(3433): ET_Builder_Section->render(Array, '[et_pb_row colu...', 'et_pb_section', '', '', '', '', '') #17 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-includesshortcodes.php(433): ET_Builder_Element->_render(Array, '[et_pb_row colu...', 'et_pb_section') #18 [internal function]: do_shortcode_tag(Array) #19 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-includesshortcodes.php(273): preg_replace_callback('/\[(\[?)(et_pb_...', 'do_shortcode_ta...', '<div class="et-...') #20 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-includesclass-wp-hook.php(324): do_shortcode('<div class="et-...') #21 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-includesplugin.php(205): WP_Hook->apply_filters('<div class="et-...', Array) #22 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-contentthemesDiviincludesbuildercore.php(26): apply_filters('et_builder_rend...', '[et_pb_section ...') #23 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-contentthemesDiviincludesbuilderfrontend-buildertheme-builderfrontend.php(347): et_builder_render_layout('[et_pb_section ...') #24 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-contentthemesDiviincludesbuilderfrontend-buildertheme-builderfrontend.php(506): et_theme_builder_frontend_render_layout('et_body_layout', 8) #25 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-contentthemesDiviincludesbuilderfrontend-buildertheme-builderfrontend-body-template.php(10): et_theme_builder_frontend_render_body(8, true, false) #26 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-includestemplate-loader.php(106): include('C:\Users\qhuser...') #27 C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-blog-header.php(19): require_once('C:\Users\qhuser...') #28 C:UsersqhuserLocal Siteswordpress-with-reactapppublicindex.php(17): require('C:\Users\qhuser...') #29 {main} thrown in C:UsersqhuserLocal Siteswordpress-with-reactapppublicwp-contentpluginstestincludesmodulesExamsExams.php on line 53

My .php file looks like this:

<?php

use MongoDBClient;

class Exams extends ET_Builder_Module
{

    public $slug       = 'test_exams';
    public $vb_support = 'on';

    protected $module_credits = array(
        'module_uri' => '',
        'author'     => 'Ilia',
        'author_uri' => '',
    );

    public function init()
    {
        $this->name = esc_html__('Exams', 'test-test');
    }

    public function get_fields()
    {
        return array(
            'content' => array(
                'label'           => esc_html__('Content', 'test-test'),
                'type'            => 'tiny_mce',
                'option_category' => 'basic_option',
                'description'     => esc_html__('Content entered here will appear inside the module.', 'test-test'),
                'toggle_slug'     => 'main_content',
            ),
        );
    }

    public function render($attrs, $content = null, $render_slug)
    {
        $mongodb_data = $this->get_mongodb_data();

        // Pass MongoDB data to React component
        $props = array(
            'content' => $content,
            'mongodbData' => $mongodb_data,
        );

        return $this->shortcode_content($props);
        // return sprintf( '<h1>%1$s</h1>', $this->props['content'] );
    }

    private function get_mongodb_data()
    {
        $uri = "mongodb://production:23yPum0%7B4O4y%3Eg%27%26b%3Fz%[email protected]:27017/?authSource=admin";

        $client = new Client($uri);

        $db = $client->selectDatabase("testyourself");
        $collection = $db->selectCollection("examtypes");

        $result = $collection->find();

        $data = [];
        foreach ($result as $document) {
            $data[] = $document;
        }

        return $data;
    }
}

new Exams ?>

<? phpinfo() ?>

My .jsx file looks like this:

// External Dependencies
import React, { Component } from "react";

// Internal Dependencies
import "./style.css";
class Exams extends Component {
  static slug = "test_exams";

  render() {
    const Content = this.props.content();
    const MongoDBData = this.props.mongodbData;

    return (
      <div>
        <h1>
          <Content />
        </h1>
        <div className="mongodb-data">
          {/* {MongoDBData.map((document, index) => console.log(document))} */}
          Hello
        </div>
      </div>
    );
  }
}

export default Exams;

I started by including mongodb in php.ini files, installation of composer + php plugin for mongo which I included into the xampp/php/ext folder. Also I ran the composer require mongodb/mongodb command in order to setup mongodb into my custom module. But now when I try to use the Exams module (which is present in the divi builder) I ran into the Uncaught Error: Class "MongoDBClient" not found in... fatal error.

When running the php.info() function it doesn’t display any support for MongoDB and says that the Loaded Configuration File is located inside C:UsersqhuserAppDataRoamingLocalrun5khIdGuD6confphpphp.ini. However, when I run the php -m command inside powershell, I can see that mongodb is there. When executing the php --ini command, the Loaded Configuration File is located inside C:xamppphpphp.ini. It may be a problem with configuration or something?

Also I am in development right now, but want to use that module in other websites, so how can I setup everything to work properly in other website too, without additional (or with minimal) changes and without doing setup for several php.ini files?

New contributor

Jon_02 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật