MongoDB can be easily integrated with Drupal 7 to support millions of dynamic web pages on a daily basis to speed up the websites. This document oriented application is a schema less database that can store large files without complicating your stack.
Here’s a look at how to install MongoDB on Linux and integrated it with Drupal 7.
1. Installing the MongoDB packages.
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 #<a href="https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ #">https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ #</a> ubuntu 14.04 echo "deb [ arch=amd64 ] <a href="https://repo.mongodb.org/apt/ubuntu">https://repo.mongodb.org/apt/ubuntu</a> trusty/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list #ubuntu 16.04 echo "deb [ arch=amd64,arm64 ] <a href="https://repo.mongodb.org/apt/ubuntu">https://repo.mongodb.org/apt/ubuntu</a> xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list #ubuntu 18.04 echo "deb [ arch=amd64 ] <a href="https://repo.mongodb.org/apt/ubuntu">https://repo.mongodb.org/apt/ubuntu</a> bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list # update package sudo apt-get update #install sudo apt-get install -y mongodb-org # start , stop , restart sudo service mongod start sudo service mongod stop sudo service mongod restart #verify #check /var/log/mongodb/mongod.log file [initandlisten] waiting for connections on port 27017
2. Installing the MongoDB PHP driver using Pecl
# PEAR is installed to put in place a package and distribution system that is used by both PEAR and PECL $ sudo apt-get install php-pear # The php7-dev package when installed lets you access the PHP5 source files that are needed to compile additional modules: $ sudo apt-get install php7-dev #Pecl is the preferred way to install the MongoDB driver. $ pecl install mongo # Add the mongo extension to /etc/php/apache2/php7.2/cli/php.ini file to Configuring PHP To Use The Driver. extension=mongo.so
3. Configuring Drupal to use MongoDB plugin
# download mongodb module $ drush dl mongodb #local.settings.php $ touch sites/default/local.settings.php # Add code to local.settings.php file #MongoDB $conf['mongodb_connections'] = array( 'default' => array( // Connection name/alias 'host' => 'localhost', // Omit USER:PASS@ if Mongo isn't configured to use authentication. 'db' => 'YOURDATABASENAME' // Database name. Make something up, mongodb will automatically create the database. ), ); include_once('./includes/cache.inc'); # -- Configure Cache $conf['cache_backends'][] = 'sites/SITENAME/modules/mongodb/mongodb_cache/mongodb_cache.inc'; $conf['cache_class_cache'] = 'DrupalMongoDBCache'; $conf['cache_class_cache_bootstrap'] = 'DrupalMongoDBCache'; $conf['cache_default_class'] = 'DrupalMongoDBCache'; # -- Don't touch SQL if in Cache $conf['page_cache_without_database'] = TRUE; $conf['page_cache_invoke_hooks'] = FALSE; # Session Caching $conf['session_inc'] = 'sites/SITENAME/modules/mongodb/mongodb_session/mongodb_session.inc'; $conf['cache_session'] = 'DrupalMongoDBCache'; # Field Storage $conf['field_storage_default'] = 'mongodb_field_storage'; # Message Queue $conf['queue_default_class'] = 'MongoDBQueue';
4. Enable mongoDB module
#Enable $ drush en mogodb
MongoDB README.txt file
CONTENTS OF THIS FILE --------------------- * Introduction * Installation * Variables * Collections * Module specific configuration INTRODUCTION ------------ MongoDB integration for Drupal. This module is a collection of several modules, allowing to store different Drupal data in MongoDB. mongodb Support library for the other modules. mongodb_block Store block information in MongoDB. Very close to the core block API. mongodb_cache Store cache in MongoDB. mongodb_field_storage Store fields in MongoDB. mongodb_queue DrupalQueueInterface implementation using MongoDB. mongodb_session Store sessions in MongoDB. mongodb_watchdog Store watchdog messages in MongoDB. INSTALLATION & CONFIGURATION ------------ Install as usual, see <a href="http://drupal.org/node/895232">http://drupal.org/node/895232</a> for further information. The MongoDB module and sub-modules need some amount of configuration before they will properly work. This guide assumes that a MongoDB instance is already installed and configured on localhost or remote server. This module additionally provides Drush integration to make queries against the MongoDB databases used by Drupal. If MongoDB is installed on localhost, you may view the web admin interface: > <a href="http://localhost:28017/ VARIABLES ------------ MongoDB">http://localhost:28017/ VARIABLES ------------ MongoDB</a> uses several specific configuration variables that are not currently exposed in the UI. Non-developers should note that all $conf variables should Configuration Variables #1: mongodb_connections The mongodb_connections variable holds the databases available to the module. the connection, the database address, and the name of the database. If not EXAMPLE: // Connection name/alias // Omit USER:PASS@ if Mongo isn't configured to use authentication. 'host' => 'mongodb://USER:<a href="mailto:PASS@localhost">PASS@localhost</a>', // Database name 'db' => 'drupal_default', ), ); created with the following settings: Also, connection_options might be specified to allow for connecting to replicate sets (and any other options listed on <a href="http://www.php.net/manual/mongo.construct.php">http://www.php.net/manual/mongo.construct.php</a>) // Connection name/alias 'host' => 'host1,host2,host3', // Database name 'db' => 'drupal_default', ), ); #2: mongodb_debug A variable primarily for developers, mongodb_debug causes a collection to return a mongoDebugCollection and mongoDebugCursor instead of their EXAMPLE: $conf['mongodb_debug'] = FALSE; #3: mongodb_session This variable holds the name of the collection used by the mongodb_session EXAMPLE: $conf['mongodb_session'] = 'anyname'; #4: mongodb_slave This variable holds an array of the slaves used for the mongodb field storage #5: mongodb_watchdog This variable holds the name of the collection used by the mongodb_watchdog module. It defaults to "watchdog". EXAMPLE: $conf['mongodb_watchdog'] = 'drupalogs'; #6: mongodb_watchdog_items This variable defines the maximum item limit on the capped collection used by The actual (size-based) limit is derived from this variable, assuming 1 kiB per watchdog entry. EXAMPLE: $conf['mongodb_watchdog_items'] = 15000; #7: watchdog_limit This variable define the maximum severity level to save into watchdog. Errors saved. EXAMPLE: $conf['watchdog_limit'] = WATCHDOG_CRITICAL; See <a href="http://api.drupal.org/api/drupal/includes--common.inc/function/watchdog_severity_levels/7 ">http://api.drupal.org/api/drupal/includes--common.inc/function/watchdog_...</a> for further information about Watchdog severity levels. #8: mongodb_collections See COLLECTIONS below. COLLECTIONS ------------ Collections are MongoDB's equivalent of relational database tables. In the context of this module, they can be used to span data from the multiple submodules into separate databases. This is accomplished by aliasing the collection name to a connection name (as defined in the 'mongodb_connections' variable). If you want everything in a single database, collections do not need to be configured and everything is written to the local default database using the default collection names (given below). The dot is allowed in the name of mongodb collections. Before the dot, mongodb_field_storage uses "fields_current" or "fields_revision" and puts the entity type after. MODULE COLLECTION NAMES ----------------------------------------------------------- mongodb_block "block" mongodb_cache "cache_bootstrap" "cache_menu" ... mongodb_field_storage "fields_current.node", "fields_current.taxonomy_term" "fields_revision.user" ... mongodb_queue "queue."<queue name foo> "queue."<queue name bar> ... mongodb_session "session" (variable) mongodb_watchdog "watchdog" (variable) ----------------------------------------------------------- In the following example, the watchdog collection will be handled by the hypothetical connection alias 'logginghost' EXAMPLE: $conf['mongodb_collections'] = array('watchdog' => 'logginghost'); MODULE-SPECIFIC CONFIGURATION ------------ The following configuration variables are needed to use the features provided by the the following sub-modules. => mongodb_cache EXAMPLE: # -- Configure Cache $conf['cache_backends'][] = 'sites/all/modules/mongodb/mongodb_cache/mongodb_cache.inc'; $conf['cache_default_class'] = 'DrupalMongoDBCache'; $conf['page_cache_without_database'] = TRUE; $conf['page_cache_invoke_hooks'] = FALSE; => mongodb_session EXAMPLE: # Session Caching $conf['session_inc'] = 'sites/all/modules/mongodb/mongodb_session/mongodb_session.inc'; $conf['cache_session'] = 'DrupalMongoDBCache'; => mongodb_field_storage EXAMPLE: # Field Storage $conf['field_storage_default'] = 'mongodb_field_storage'; TROUBLESHOOTING ------------ If installing mongodb_field_storage from an Install Profile: * Do not include the module specific $conf variable in settings.php during install. * In the profiles hook_install() function include drupal_flush_all_caches();