No AuthProvider for DEFAULT defined

Viewed 9164

My MongoDB Compass has updated to version 1.28.1 and now I can't connect to my mongo host. The error is

No AuthProvider for DEFAULT defined.

I don't use authentication, so my connection string is without username and password. How to fix the problem?

6 Answers

When you first create new connection, the connection string looks like

mongodb://some-remote-host/database

Then MongoDb Compass saves connection to favorites modifying the connection string to

mongodb://some-remote-host:27017/database?readPreference=primary&authSource=database&appname=MongoDB%20Compass&directConnection=true&ssl=false

To make MongoDB Compass connect again you need to remove this parameter from connection string:

&authSource=database

Restarting the MongoDB Compass will solve this problem.

For a passwordless/userless connection, making sure the connection url doesn't contain authSource worked for me.

Replace

mongodb://some-remote-address:27017/database?readPreference=primary&authSource=database&directConnection=true&ssl=false

with

mongodb://some-remote-address:27017/database?readPreference=primary&directConnection=true&ssl=false

changing it to mongodb://localhost:27017 didn't work initially, I actually had to restart MongoDB Compass :/

I solved it by following steps (for Node.js application) ...

  • Under Database navigation panel click on 'Connect' for your Cluster [Cluster0]
  • from new window select 'Connect to Application' option
    choose your driver (Node.js for me) and it's version
  • After that you see Connection String

mongodb+srv://<username>:<password>@cluster0.olwls.mongodb.net/myFirstDatabase?retryWrites=true&w=majority

Note: change username and password with your creds

This worked for me

    mongoose.connect(
    `mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASS}@cluster0.adv0t.mongodb.net/${process.env.MONGO_DATABASE}?retryWrites=true&w=majority`,
    {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    }
  );

Create a ".env" file (you need to install dotenv before this ) in the parent directory(if you choose a custom location, add the following).

require('dotenv').config({ path: '/custom/path/to/.env' }) //uses custom location

Otherwise, add this in the server.js/app.js the one that initiates server.

require('dotenv').config() //uses default location

In the ".env" file, define the user, password and database like this

MONGO_USER=uSerName
MONGO_PASS=p@sSW0rd
MONGO_DATABASE=myDatabase
Related