Search code examples
mongodbpasswordslithium

MongoDB password and Lithium framework


I came across a scenario in which the MongoDB password was removed from the DB. Then Lithium showed "Connection was reset.. ", instead of lithium error.

I will explain you step by step:

In Connections.php

Connections::add('default', array(
 'type' => 'MongoDb',
 'host' => 'localhost',
 'database' => 'CWMG'
));

Added user in Mongo:

C:\>Mongo
> use CWMG
> db.addUser('mongo','awesomeness');

Change Connections.php

Connections::add('default', array(
  'type' => 'MongoDb',
  'host' => 'localhost',
  'database' => 'CWMG',
  'login' => 'mongo',
  'password' => 'awesomeness'
));

Now remove the user from Mongo

db.removeUser('mongo');

Change the connection Connections.php - now not using password...

Connections::add('default', array(
 'type' => 'MongoDb',
 'host' => 'localhost',
 'database' => 'CWMG'
));

Now, Connections.php will not work; If you browse the site.. we get an error: "Connection was reset", some times it will redirect to another website.

Lost connection on page

The only solution, I found, is to add the user back in MongoDB and also the same in Lithium.

So my question is how do I remove a user from MongoDB, once added?


Solution

  • Finally, I found the solution. It is MongoDB which stores the password association. To remove it I first tried

    1. Export Mongo Database
    2. Stopped the service
    3. Delete Mongo Database
    4. Started the service
    5. Imported Mongo Database

    Checked for the solution.

    Same problem

    So I tried the final and the only solution:

    1. Export Mongo Database
    2. Stopped the service
    3. Deleted the MongoDB folder
    4. Installed Mongo again
    5. Started the service
    6. Imported Mongo Database

    Yes! It is now working OK!