Closed (fixed)
Project:
MongoDB
Version:
7.x-1.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
17 Jan 2013 at 17:45 UTC
Updated:
24 Jun 2018 at 11:09 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
Alexander Matveev commentedIn mongodb.module changed this:
to this:
And it works.
Comment #2
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 commentedfrom #1 work for me too
Comment #4
ikhlasstudio commentedYou can try with drupal database 's user instead admin database 's user
Comment #5
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 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 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
Anonymous (not verified) commentedTested D7 patch only, the D8 patch needs to be re-roled (if still needed).
Comment #10
Anonymous (not verified) 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
Anonymous (not verified) 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