Question

I have copied my project from production environment into dev environment and so needed to update configs to the ones used for dev environment.

I updated the in app/etc/mongogento.xml and other config files but my Mage code still selects the production mongodb server ("dbserver:27017") instead of the dev mongodb server ("localhost:27017"). I have done a global search but I don't see "dbserver" mentioned anywhere. Tried restarting nginx abd php-fpm too to see if a value from cache is being used but i still get the same error:

Fatal error: Uncaught MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers found (`serverSelectionTryOnce` set): [connection timeout calling ismaster on 'dbserver:27017'] in /var/www/api/vendor/mongodb/mongodb/src/functions.php:431 Stack trace: #0 /var/www/api/vendor/mongodb/mongodb/src/functions.php(431): MongoDB\Driver\Manager->selectServer() #1 /var/www/api/vendor/mongodb/mongodb/src/Collection.php(651): MongoDB\select_server() #2 /var/www/api/app/code/community/Smile/MongoCore/Model/Resource/Override/Core/Store/Collection.php(92): MongoDB\Collection->find() #3 /var/www/api/lib/Varien/Data/Collection.php(752): Smile_MongoCore_Model_Resource_Override_Core_Store_Collection->load() #4 /var/www/api/app/code/core/Mage/Core/Model/App.php(636): Varien_Data_Collection->count() #5 /var/www/api/app/code/core/Mage/Core/Model/App.php(477): Mage_Core_Model_App->_initStores() #6 /var/www/api/app/code/core/Mage/Core/Model/App.php(285): Mage_Core_Model_App->_initCurrentStore() #7 /var/www/api/app/Mage.php(627): Mag in /var/www/api/vendor/mongodb/mongodb/src/functions.php on line 431

Note that mongo db connection using MongoDB Client works properly since I am explicitly mentioning the server name like so:

$client = new MongoDB\Client("mongodb://localhost:27017");

My test code producing the error:

$root = (filter_input(INPUT_SERVER, 'DOCUMENT_ROOT'));
require $root. '/vendor/autoload.php'; // include Composer's autoloader
require_once $root . '/app/Mage.php';
Mage::app('admin');
Was it helpful?

Solution

Turns out, Magento was reading the server configuration from redis database instead of from it's config file. Deleting all data from the database solved it for me.

OTHER TIPS

To change your Magento 2 database server hostname, database username, password or database name, you need to edit below file.

//app/etc/env.php Navigate to your Magento 2 installation directory and edit app/etc/env.php configuration file in your favorite editor and search for following settings and do necessary changes.

'db' => array ( 'table_prefix' => '', 'connection' => array ( 'default' => array ( 'host' => 'localhost', 'dbname' => 'database_name', 'username' => 'database_username', 'password' => 'database_password', 'active' => '1', ), ), ),

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top