No AuthProvider for DEFAULT defined
Asked Answered
L

7

10

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?

Lent answered 26/7, 2021 at 7:47 Comment(5)
I use Compass 1.28.1 against a local database with auth turned off. I simply use the connection string mongodb://localhost:27017. It seems that when I start typing in the connection string I see a message "No username provided in the authority section" but that goes away after completing the connection string. Perhaps you are on a different screen than I am. If you are trying to use a saved connection string, perhaps try to delete it and re-add it to square things up.Teneshatenesmus
Thanks for your reply. I deleted all connections from favorite list and from recent list and created new connection. Result is the same error. My connection string looks like mongodb://some-remote-address:27017/database?readPreference=primary&authSource=database&directConnection=true&ssl=falseLent
Your example connection string refers to host "some-remote-address". It could be that this host is unreachable on port 27017, or that the installed mongodb requires authentication? I am just guessing...Teneshatenesmus
The host is reachable on port 27017 and mongodb does not require authentication. This connection works in IntelliJ DataGrip and NoSQLBooster for MongoDB, but does not work in MongoDB Compass.Lent
I was just trying to get rid of this error for a like half an hour. Restarting MongoDB Compass worked 🤷‍♂️Privatdocent
L
8

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
Lent answered 7/10, 2021 at 9:21 Comment(0)
J
6

Restarting the MongoDB Compass will solve this problem.

Jimmy answered 28/8, 2021 at 12:20 Comment(7)
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context.Blennioid
I tried to restart MongoDB Compass and this has no effect. I tried to reinstall MongoDB Compass - the problem was not solved. It looks like some kind of a bug in MongoDB Compass app. In previous versions of the app I didn't have this problem.Lent
@VasliSlavik Try connecting with Robo3T and check if It's really the issue regarding MongoDB Compass or actually inside the server. I hope you already edited /etc/mongod.conf and in ip added 0.0.0.0 instead of 127.0.0.1. Let me know the error in detail and I'll try to help. Thanks.Jimmy
I downloaded and installed 1.27.0-beta.10 (Beta) version of MongoDB Compass app. It works fine. It seems that the problem occurs only in 1.28. Moreover, I found a way to reproduce the problem: 1. Create new connection and use this connection string: mongodb://some-remote-host/database Connection string should not have any port or any additional settings. This connections works fine.Lent
2. After exiting MongoDB Compass and starting it again MongoDB Compass shows in recent list the last used connection string. But it is a little bit modified by the app. Now connection string looks like mongodb://some-remote-host:27017/database?readPreference=primary&authSource=database&appname=MongoDB%20Compass&directConnection=true&ssl=false This new connection string that was modified by the app is not working.Lent
In 1.27.0-beta.10 (Beta) new connection string that was modified by app works fine.Lent
@VasliSlavik I would suggest you to use Robo 3T or MongoDB Community Compass and not the "MongoDB Compass".Jimmy
P
1

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
Peripatetic answered 15/9, 2021 at 9:36 Comment(0)
M
1

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

Murphey answered 20/11, 2021 at 2:56 Comment(0)
R
1

For my case, I'm missed to have input for the username. So make sure you double check the required fields.

Reunion answered 8/4, 2023 at 8:3 Comment(0)
C
0

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

Calica answered 9/10, 2021 at 16:56 Comment(0)
W
0

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
Woodprint answered 12/10, 2021 at 12:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.