Resolving Heroku application Error - Failed to authenticate user 'heroku' on db - Mongo::AuthenticationError
Apr 28, 2013
Suresh Vasudev
2 minute read

Problem Scenario

I was revamping a Locomotive CMS application from scratch. As a part of deployment of this new application, I copied the MongoDB database from its previous version to the new app. However on accessing the application after deployment I got the following error.

Heroku Application Error

This is a very generic error message and to get into the actual root cause I checked the application log. It contains the following error.

Failed to authenticate user ‘heroku’ on db ‘{My Application Database Name}’ (Mongo::AuthenticationError)

To check the application logs use the following command

*>> heroku logs –app {Application Name}*

Root cause

When I copied the database from my previous application, it also copied all system tables including “users”. This overrides the existing users defined in the database with the new users. My old and new application contains this user - “heroku” which is the default user created when adding the mongoHQ addon. The password for this user will be auto-generated by the system initially.

Now on copying the database, the password got changed and it is not matching with the password defined in the environment variable - MONGOHQ_URL


Get the value set for the environment variable - MONGOHQ_URL for the application.

*>> heroku config –app {appname}*

One of the environment variables will be MONGO_URL, which defines the database connection information.

MONGOHQ_URL: mongodb://

The URL format is as follows


Solution -1: Reset the password for user – heroku in MongoDB database

[1] Go to the Heroku console and click on the MongoDB addon. It will open up the administrative console for the database in a new browser window.

Heroku Application Console

[2] In the administrative console, select the Admin-> Users option to see the list of all users of this database.

MongoHQ Administrative Console

[3] Using the “Change Password” option, change the password of “heroku” user with one defined in MONGO_URL

MONGOHQ_URL: mongodb://

In this example, 2a85b is the password

Solution -2: Change the password in MONGO_URL

You can use this solution if you know the password of ‘heroku” user in the previous application database. All we need here is modify the environment variable – MONGO_URL with the correct password.

[1] Get the MOGO_URL environment variable defined for the application

*>> heroku config –app {Application Name}*

MONGOHQ_URL: mongodb://

[2] Update the Environment variable with the correct password.

If the password is ‘abc123” then

>> heroku config:add MONGOHQ_URL=mongodb://


Now check the application to see this issue resolved.