1

I set up a mongodb database using the MongoLab add-on on heroku. My deployment (which is just a REST API) successfully builds, yet when I go to the site, all I see in my browser is this error:

{"name":"MongoError","message":"not authorized for query on heroku_2vlv3f28.tags","$err":"not authorized for query on heroku_2vlv3f28.tags","code":13}

I've also checked to make sure I'm using the correct credentials when connecting using mongoose in my index.js file.

The connection part of my index.js file is:

// Connect to MongoDB                                                                                                                                                                                      
mongoose.connect('mongodb://<MY DB USERNAME>:<MY PASSWORD>@ds027415.mongolab.com:27415/heroku_2vlv3f28');
mongoose.connection.once('open', function() {

    // Load the models.                                                                                                                                                                                    
    app.models = require('./models/index');

    // Load the routes.                                                                                                                                                                                    
    var routes = require('./routes');
    _.each(routes, function(controller, route) {
        app.use(route, controller(app, route));
    });

    console.log('Listening on port 3000...');
    server.listen(process.env.PORT || 3000);

I've also tried adding ?authMode=scram-sha1 into the mongoose.connect line, which I tried because I saw it here (it didn't fix the problem)

Community
  • 1
  • 1
saila
  • 23
  • 3

1 Answers1

0

So finally, are you sure you're using the right credentials? If not, you can get your database username and password using:

heroku config | grep MONGODB_URI

The response is in this format:

MONGOLAB_URI: mongodb://username:password@mlab.com:12345/db

Aboozar Rajabi
  • 1,683
  • 21
  • 26