How to Integrate Drupal9 MongoDB ?

Submitted by sysop on Sat, 09/16/2023 - 17:03

Integrate Drupal9 MongoDB

Integrating Drupal9 with MongoDB involves using MongoDB as the backend database for storing and retrieving content, configuration, and other data used by your Drupal site. This integration can offer several advantages, such as improved performance, scalability, and flexibility in managing content.

Drupal is a popular open-source content management system (CMS) used for building and managing websites and web applications. MongoDB, on the other hand, is a NoSQL database that stores data in a flexible, JSON-like format, making it suitable for handling large volumes of unstructured or semi-structured data. It's particularly well-suited for projects with evolving data schemas and high scalability requirements.

Here's a general guide on how to Integrate Drupal9 MongoDB:

Note: This guide assumes that you have already installed MongoDB server and you are using drupal9/10.

  1. Install MongoDB php8.1 extension.
    sudo apt-get install php8.1-mongodb
  2. Then verify if the extension is enabled with the below command:
    php -i | grep mongo
  3. If the extension is not enabled, kindly add the below line to your php.ini file and restart the apache and php-fpm services.
  4. Next, install the MongoDB drupal module. We recommend using composer for this.
    composer require 'drupal/mongodb:^2.1@alpha'
  5. Next, enable the module with drush command or by navigating to Drupal's module 'Extend' page.
    drush en mongodb mongodb_storage -y
  6. Now, open your settings.php file and add the below lines at the bottom of the file and save. Make sure to edit your "mongoDB client alias and database alias". Also, if the mongoDB server is on different host. Make sure to edit the IP properly.
      $settings['mongodb'] = [
        'clients' => [
          // Client alias => connection constructor parameters.
          'your_mongo_client_alias' => [
            'uri' => 'mongodb://localhost:27017',
            'driverOptions' => [],
        'databases' => [
          // Database alias => [ client_alias, database_name ].
          'example_mongodb' => ['your_mongo_client_alias', 'example_mongodb'],
          'logger' => ['your_mongo_client_alias', 'your_logger_alias'],
  7. Now, enable the mongodb_watchdog module. It requires logger alias to be configured as above.
    drush en mongodb_watchdog
  8. If you have configured everything properly, then you must see "valid configuration" on your Drupal Status report page.

    How to configure Drupal with MongoDB

    Congratulations you have Integrated Drupal9 MongoDB. Hope this Documentation helps!!!