question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`authdb` option not working

See original GitHub issue

using

    var connectionString = 'mongodb://' + config.database.username + ':' + config.database.password + '@' + config.database.host + ':' + config.database.port + '/' + dbname;
    var connection = mongoose.createConnection(connectionString);

everything is replaced fine. user is create via mongo shell db.addUser() and has role ‘readWriteAnyDatabase’. User can connect via mongo shell and query the db. But not via mongoose.

    MongoError: not authorized for query on punch.shops
    >>     at Object.toError (/var/www/virtual/punch/html/punch/node_modules/mongoose/node_modules/mongodb/lib/mongodb/utils.js:110:11)
    >>     at /var/www/virtual/punch/html/punch/node_modules/mongoose/node_modules/mongodb/lib/mongodb/cursor.js:634:54
    >>     at Cursor.close (/var/www/virtual/punch/html/punch/node_modules/mongoose/node_modules/mongodb/lib/mongodb/cursor.js:903:5)
    >>     at commandHandler (/var/www/virtual/punch/html/punch/node_modules/mongoose/node_modules/mongodb/lib/mongodb/cursor.js:634:21)
    >>     at /var/www/virtual/punch/html/punch/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1670:9
    >>     at Server.Base._callHandler (/var/www/virtual/punch/html/punch/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:382:41)
    >>     at /var/www/virtual/punch/html/punch/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:472:18
    >>     at MongoReply.parseBody (/var/www/virtual/punch/html/punch/node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
    >>     at null.<anonymous> (/var/www/virtual/punch/html/punch/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:430:20)
    >>     at EventEmitter.emit (events.js:95:17)
    >> Exited with code: 8.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:25

github_iconTop GitHub Comments

10reactions
frty2commented, Oct 18, 2013

After hours of debugging I found the solution: use the authdb option.

     var opt = {
            user: config.database.username,
            pass: config.database.password,
            auth: {
                authdb: 'admin'
            }
        };

        var connection = mongoose.createConnection(config.database.host, 'mydatabase', config.database.port, opt);
5reactions
thevincicommented, Oct 29, 2014

For some reason I am able to connect to the admin database and create records with no problems.

This is how I am connecting:

var options = {
   user: USER,
   pass: PASS,
   auth: {
       authdb: 'admin'
   }
};

var db = mongoose.connect('localhost', 'database', 28017, options);
Read more comments on GitHub >

github_iconTop Results From Across the Web

MongoError: auth failed mongoose connection string
I installed MEAN from MEAN packaged by Bitnami for windows 7 using the following password: 123456. Syntax for connection string to connect ...
Read more >
Connection String URI Format — MongoDB Manual
Refer to the Drivers documentation. This connection string option is not available for the mongo shell. Use the command-line option instead. New in...
Read more >
Managing the Authorization Database in OS X Mavericks
The security authorizationdb command has three options: ... At next reboot, the OS will detect that /var/db/auth.db does not exist and ...
Read more >
External Auth db not updating password - Moodle in English
I have external db authorization turned on for the site, and have confirmed that users who are in the external db *can* log...
Read more >
Working With the Authentication Database - Oracle Help Center
The Authentication Database, also referred to as auth-db, represents a ... For example, the configuration below is equivalent to not specifying servicename: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found