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?

Vasli Slavik
  • 309
  • 2
  • 4
  • 11
  • 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. – barrypicker Jul 26 '21 at 17:47
  • 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=false – Vasli Slavik Jul 28 '21 at 14:41
  • 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... – barrypicker Jul 28 '21 at 20:56
  • 1
    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. – Vasli Slavik Jul 29 '21 at 09:03
  • 2
    I was just trying to get rid of this error for a like half an hour. Restarting MongoDB Compass worked ‍♂️ – benmneb Aug 01 '21 at 11:43

7 Answers7

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
Vasli Slavik
  • 309
  • 2
  • 4
  • 11
6

Restarting the MongoDB Compass will solve this problem.

Xavier Guihot
  • 54,987
  • 21
  • 291
  • 190
AxelBlaze
  • 183
  • 1
  • 5
  • If you have a new question, please ask it by clicking the [Ask Question](https://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. – RandallShanePhD Aug 29 '21 at 10:39
  • 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. – Vasli Slavik Aug 30 '21 at 09:58
  • @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. – AxelBlaze Aug 31 '21 at 12:29
  • 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. – Vasli Slavik Aug 31 '21 at 14:07
  • 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. – Vasli Slavik Aug 31 '21 at 14:12
  • In 1.27.0-beta.10 (Beta) new connection string that was modified by app works fine. – Vasli Slavik Aug 31 '21 at 14:14
  • @VasliSlavik I would suggest you to use Robo 3T or *MongoDB Community Compass* and not the "MongoDB Compass". – AxelBlaze Aug 31 '21 at 15:08
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
Antoine
  • 3,880
  • 2
  • 26
  • 44
1

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

Sebastian
  • 63
  • 5
1

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

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

CodeWorld
  • 2,017
  • 1
  • 11
  • 21
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
rhythmo
  • 859
  • 2
  • 9
  • 21