Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
While uninstalling Watchdog module:
MongoConnectionException: Failed to connect to: localhost:27017: Authentication failed on database 'admin' with username '[mongouser]': auth fails in Mongo->__construct() (line 34 of [path]/mongodb/mongodb.module).
Comment | File | Size | Author |
---|---|---|---|
#13 | 0001-Issue-1891508-by-SchnWalter-allow-specifying-a-datab.patch | 900 bytes | fgm |
#6 | pass_db_in_options_array-1891508-6_D8-do-not-test.patch | 518 bytes | bigjim |
Comments
Comment #1
Alexander Matveev CreditAttribution: Alexander Matveev commentedIn mongodb.module changed this:
to this:
And it works.
Comment #2
tloudon CreditAttribution: tloudon commentedHere's the full function:
That line
$mongo_objects[$host][$db] = $mongo->selectDB($db);
should set the database and it should default to 'drupal' if no 'db' element is defined in settings.php.I don't have any issues connecting to my mongo instance and I have auth enabled in the mongo.conf and set up in settings.php. Also used same code w/o a user. Outside of Drupal, if I don't specify a user or db prior to starting the mongo shell client, I can use "db.auth('user', 'pass)" and "use mydatabase". So I don't think the Mongo server restricts access prior to connection or requires user/pass/db/etc either.
What kind of config did you set up for authorization? Is that all working? My guess is that it's a config issue, but if you give more info and replication steps I can check things out.
Comment #3
protools CreditAttribution: protools commentedfrom #1 work for me too
Comment #4
ikhlasstudio CreditAttribution: ikhlasstudio commentedYou can try with drupal database 's user instead admin database 's user
Comment #5
bigjim CreditAttribution: bigjim commentedThe issue is before
$mongo_objects[$host][$db] = $mongo->selectDB($db);
is run the php driver attempts to log into the admin db by default when the connection is made. This only happens if a db is not specified in the host string. See the docs http://www.php.net/manual/en/mongo.connecting.auth.php#1 solves this issue by adding the db to the host string.
You can also solve this by adding the 'connection_options' element to you mongo_connections array in your settings file (which is kind of duplicative I know, but you don't have to hack the module :)).
I'm wondering why we even have the db element in the the mongo_connection array at all, why not just do it the way the Mongo wants? Also, the patch for #1 won't work with replcaSets. :(
Comment #6
bigjim CreditAttribution: bigjim commentedWrote a possible patch that utilized the db element of the $options array.
Added a D8 version, marked do not test.
Comment #7
fgmThis appears to be related to the general driver, not to watchdog, so retagging.
Comment #8
majorrobot CreditAttribution: majorrobot commentedBeautiful. Thanks for the tip re: changing settings.php, bigjim.
FWIW, we had this issue when we upgraded mongo from 2.2.x to 2.4.x and changed authorization of our users in Mongo to the new authorization structure introduced in 2.4. Unfortunately, once you wipe out your users with the old auth structure, so we had to change our Drupal settings. Works great so far.
Comment #9
SchnWalter CreditAttribution: SchnWalter commentedTested D7 patch only, the D8 patch needs to be re-roled (if still needed).
Comment #10
SchnWalter CreditAttribution: SchnWalter commentedWhen creating a database connection object if db is not specified, "admin" will be used. This causes issues if the user does not have permissions to access the admin database.
The database can be specified in two way, either in the $server info, or inside the $options array. @see http://php.net/manual/en/mongoclient.construct.php
The attached patch is only a re-rolling the patch from #6 which works perfectly. Please commit this D7 patch.
Thanks!
Comment #11
SchnWalter CreditAttribution: SchnWalter commentedRemoved updated patch.
Comment #12
fgmThis is far from critical but seems rather sane overall.
However:
...so resetting to CNW.
Comment #13
fgmRerolled on today's HEAD.
Comment #15
fgmTests now pass. Committed to today's 7.x-1.x HEAD, thanks.
Comment #16
fgm