You are here

README.txt in MongoDB 8

Note: most of README.txt is not valid. For now, if you want to test this:
- put the module in /modules/mongodb in the Drupal root.
- copy the drivers directory to your Drupal root.

VARIABLES
------------
MongoDB uses the $settings['mongo'] to store connection settings.  EXAMPLE:
  $settings['mongo'] = array(
    'servers' => array(
      // Connection name/alias
      'default' => array(
        // Omit USER:PASS@ if Mongo isn't configured to use authentication.
        'server' => 'mongodb://USER:PASS@localhost',
        // Database name
        'db' => 'drupal_default',
      ),
      // Connection name/alias
      'floodhost' => array(
        'server' => 'mongodb://flood.example.com',
        'db' => 'flood',
      ),
    ),
    'collections' => array(
      'flood' => 'floodhost',
    ),
  );

Using MongoDB for config storage:
----------------------------------------------------------------------
Enable the module and run drush mongo-cto. This will copy the current
configuration from SQL into MongoDB and edit services.yml and
settings.php for you.

Installing config storage into MongoDB:
----------------------------------------------------------------------
If you do not yet have a site then the friendly drush command is not
available and you need to copy-paste the following lines into settings.php:
--- CUT HERE ---
$settings['bootstrap_config_storage'] = function ($class_loader = NULL) use ($settings, &$config)  {
  if ($class_loader) {
    $class_loader->addPsr4('Drupal\mongodb\\', 'modules/mongodb/src');
  }
  if (class_exists('Drupal\mongodb\MongodbConfigStorageBootstrap')) {
    $config['core.extension']['module']['mongodb'] = 0;
    return new Drupal\mongodb\MongodbConfigStorageBootstrap(new Drupal\mongodb\MongoCollectionFactory($settings));
  }
};
--- CUT HERE ---

and the following into sites/default/services.yml:

--- CUT HERE ---
services:
  config.storage: "@mongodb.config.storage"
--- CUT HERE ---


Using MongoDB selectively:
----------------------------------------------------------------------
In the parameters: section of sites/default/services.yml remove
default_backend: mongo and add aliases for service separately.


Cache backend configuration:
----------------------------------------------------------------------

Enable mongodb.module and add this to your settings.php:

  $settings['cache']['default'] = 'cache.backend.mongodb';

This will enable MongoDB cache backend for all cache bins. If you want
to configure backends on per-bin basis just replace 'default' with
desired cache bin ('config', 'block', bootstrap', ...).

We set "expireAfterSeconds" option on {'expire' : 1} index. MongoDB will automatically
purge all temporary cache items TTL seconds after their expiration. Default value
for TTL is 300. This value can be changed by adding this lime to settings.php
(replace 3600 with desired TTL):

  $settings['mongo']['cache']['ttl'] = 3600;


KeyvalueMongodb backend configuration:
-----------------------------------------------------------------------

Works very similar as cache backends. To enable mongo KeyvalueMongodb store for all
keyvalue collections put this in settings.php:

  $settings['keyvalue_default'] = 'mongodb.keyvalue';

For expirable collections:

  $settings['keyvalue_expirable_default'] = 'mongodb.keyvalue';

This will set mongo as default backend. To enable it on per-collection basis use
(replace [collection_name] with a desired keyvalue collection - state, update, module_list, etc.):

  $settings['keyvalue_service_[collection_name]'] = 'mongodb.keyvalue';

or

  $settings['keyvalue_expirable_service_[collection_name]'] = 'mongodb.keyvalue';

We use "TTL" mongo collections for expirable keyvalue service. You can set TTL by
adding this line to settings.php.

  $settings['mongo']['keyvalue']['ttl'] = 3600;

Note that takeover module supports keyvalue as well:

drush takeover mongodb.keyvalue

will copy everything from the keyvalue SQL table to the mongodb collection.

QueueMongodb backend configuration:
-----------------------------------------------------------------------

Works very similar as cache backends. To enable mongo queue store for all
queues put this in settings.php:

  $settings['queue_default'] = 'queue.mongodb';

This will set mongo as default backend. To enable it on per-queue basis use
(replace [queue_name] with a desired queue):

  $settings['queue_service_[queue_name]'] = 'queue.mongodb';

or for reliable queues:

  $settings['queue_reliable_service_[queue_name]'] = 'queue.mongodb';

Watchdog module:
------------------------------------------------------------------------

The CSS in the watchdog module assumes the module to be installed in
modules/mongodb to locate the core report icon files correctly.

Testing with MongoDB:
------------------------------------------------------------------------

A core patch is included, after applying it, the settings.testing.php will be
incldued with every web-test and the relevant MongoDB modules will be enabled.
Ie. when running aggregator tests, mongodb_aggregator.module will be enabled
and it will provide aggregator storage. For non-web based tests, the
$test_settings variable can be used instead of $settings to add new settings.
This is ongoing work.

File

README.txt
View source
  1. Note: most of README.txt is not valid. For now, if you want to test this:
  2. - put the module in /modules/mongodb in the Drupal root.
  3. - copy the drivers directory to your Drupal root.
  4. VARIABLES
  5. ------------
  6. MongoDB uses the $settings['mongo'] to store connection settings. EXAMPLE:
  7. $settings['mongo'] = array(
  8. 'servers' => array(
  9. // Connection name/alias
  10. 'default' => array(
  11. // Omit USER:PASS@ if Mongo isn't configured to use authentication.
  12. 'server' => 'mongodb://USER:PASS@localhost',
  13. // Database name
  14. 'db' => 'drupal_default',
  15. ),
  16. // Connection name/alias
  17. 'floodhost' => array(
  18. 'server' => 'mongodb://flood.example.com',
  19. 'db' => 'flood',
  20. ),
  21. ),
  22. 'collections' => array(
  23. 'flood' => 'floodhost',
  24. ),
  25. );
  26. Using MongoDB for config storage:
  27. ----------------------------------------------------------------------
  28. Enable the module and run drush mongo-cto. This will copy the current
  29. configuration from SQL into MongoDB and edit services.yml and
  30. settings.php for you.
  31. Installing config storage into MongoDB:
  32. ----------------------------------------------------------------------
  33. If you do not yet have a site then the friendly drush command is not
  34. available and you need to copy-paste the following lines into settings.php:
  35. --- CUT HERE ---
  36. $settings['bootstrap_config_storage'] = function ($class_loader = NULL) use ($settings, &$config) {
  37. if ($class_loader) {
  38. $class_loader->addPsr4('Drupal\mongodb\\', 'modules/mongodb/src');
  39. }
  40. if (class_exists('Drupal\mongodb\MongodbConfigStorageBootstrap')) {
  41. $config['core.extension']['module']['mongodb'] = 0;
  42. return new Drupal\mongodb\MongodbConfigStorageBootstrap(new Drupal\mongodb\MongoCollectionFactory($settings));
  43. }
  44. };
  45. --- CUT HERE ---
  46. and the following into sites/default/services.yml:
  47. --- CUT HERE ---
  48. services:
  49. config.storage: "@mongodb.config.storage"
  50. --- CUT HERE ---
  51. Using MongoDB selectively:
  52. ----------------------------------------------------------------------
  53. In the parameters: section of sites/default/services.yml remove
  54. default_backend: mongo and add aliases for service separately.
  55. Cache backend configuration:
  56. ----------------------------------------------------------------------
  57. Enable mongodb.module and add this to your settings.php:
  58. $settings['cache']['default'] = 'cache.backend.mongodb';
  59. This will enable MongoDB cache backend for all cache bins. If you want
  60. to configure backends on per-bin basis just replace 'default' with
  61. desired cache bin ('config', 'block', bootstrap', ...).
  62. We set "expireAfterSeconds" option on {'expire' : 1} index. MongoDB will automatically
  63. purge all temporary cache items TTL seconds after their expiration. Default value
  64. for TTL is 300. This value can be changed by adding this lime to settings.php
  65. (replace 3600 with desired TTL):
  66. $settings['mongo']['cache']['ttl'] = 3600;
  67. KeyvalueMongodb backend configuration:
  68. -----------------------------------------------------------------------
  69. Works very similar as cache backends. To enable mongo KeyvalueMongodb store for all
  70. keyvalue collections put this in settings.php:
  71. $settings['keyvalue_default'] = 'mongodb.keyvalue';
  72. For expirable collections:
  73. $settings['keyvalue_expirable_default'] = 'mongodb.keyvalue';
  74. This will set mongo as default backend. To enable it on per-collection basis use
  75. (replace [collection_name] with a desired keyvalue collection - state, update, module_list, etc.):
  76. $settings['keyvalue_service_[collection_name]'] = 'mongodb.keyvalue';
  77. or
  78. $settings['keyvalue_expirable_service_[collection_name]'] = 'mongodb.keyvalue';
  79. We use "TTL" mongo collections for expirable keyvalue service. You can set TTL by
  80. adding this line to settings.php.
  81. $settings['mongo']['keyvalue']['ttl'] = 3600;
  82. Note that takeover module supports keyvalue as well:
  83. drush takeover mongodb.keyvalue
  84. will copy everything from the keyvalue SQL table to the mongodb collection.
  85. QueueMongodb backend configuration:
  86. -----------------------------------------------------------------------
  87. Works very similar as cache backends. To enable mongo queue store for all
  88. queues put this in settings.php:
  89. $settings['queue_default'] = 'queue.mongodb';
  90. This will set mongo as default backend. To enable it on per-queue basis use
  91. (replace [queue_name] with a desired queue):
  92. $settings['queue_service_[queue_name]'] = 'queue.mongodb';
  93. or for reliable queues:
  94. $settings['queue_reliable_service_[queue_name]'] = 'queue.mongodb';
  95. Watchdog module:
  96. ------------------------------------------------------------------------
  97. The CSS in the watchdog module assumes the module to be installed in
  98. modules/mongodb to locate the core report icon files correctly.
  99. Testing with MongoDB:
  100. ------------------------------------------------------------------------
  101. A core patch is included, after applying it, the settings.testing.php will be
  102. incldued with every web-test and the relevant MongoDB modules will be enabled.
  103. Ie. when running aggregator tests, mongodb_aggregator.module will be enabled
  104. and it will provide aggregator storage. For non-web based tests, the
  105. $test_settings variable can be used instead of $settings to add new settings.
  106. This is ongoing work.