Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We have an external mongodb instance and we need to query data from it and bring it to Drupal 8 site.
On shell this is how we connect
mongo --host docker_mongo --ssl --sslCAFile=/etc/ssl/mongodb-cert.crt
Could anyone suggest how to connect to a mongodb instance?
Adding the following at settings.php does not work and status report shows "No database aliases found in settings. Did you actually configure your settings ?"
$configureMongoDb = function (array $settings): array {
$settings['mongodb'] = [
'clients' => [
// Client alias => connection constructor parameters.
'mymongo' => [
'uri' => 'mongodb://docker_mongo:27017',
'uriOptions' => ['ssl=true&sslCAFile=/etc/ssl/mongodb-cert.crt'],
'driverOptions' => [],
],
],
'databases' => [
// Database alias => [ client_alias, database_name ].
'tutorial2' => ['mymongo', 'tutorial2'],
],
];
return $settings;
};
Cross posted this query on drupal.stackexchange as well.
Comments
Comment #2
toamit CreditAttribution: toamit commentedComment #3
toamit CreditAttribution: toamit commentedComment #4
fgmThe fragment you show defines a closure performing the configuration, and seems correct.
But did you call it further down in your settings.php file ? Because if you don't it's just a function and doesn't do anything until you call it like:
Comment #5
fgmComment #6
fgmFixing version: 8.x-1.x is not supported, and this style of settings belongs to the 8.x-2.x branch.
Comment #7
toamit CreditAttribution: toamit commentedThanks, I had another issue as pecl install mongodb was not installing ssl which caused failure to connect with mongoldb
Comment #8
fgmThanks for closing the issue. Do you feel the doc or code could have helped you find the issue faster ? and if so how ?
Comment #9
toamit CreditAttribution: toamit commented@fgm I was hoping to provide documentable information, but could not provide it, so atleast mention it here.
It would be nice include the following in readme and documentation.
Another convenience that the module could provide is to add a button say "Test connection" in module configuration, this way we don't have to sieve through status report. The button would display success or error message in the UI.
Thanks for the module and being thoughtful on how documentation can be improved, which is quite rare in contributed or even core space.
Comment #10
fgmThanks for the suggestion, follow-up issue added as #3023469: Add a configuration check in the UI.