admin管理员组

文章数量:1393900

Trying to set up MongoDB for my Node.JS application. I running this mand:

mongo "mongodb+srv://cluster0-gjc2u.mongodb/test"  --username <myusername>

And getting this response every single time.

MongoDB shell version v4.2.1
Enter password:
connecting to: mongodb://cluster0-shard-00-00-gjc2u.mongodb:27017,cluster0-shard-00-01-gjc2u.mongodb:27017,cluster0-shard-00-02-gjc2u.mongodb:27017/test?authSource=admin&pressors=disabled&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0&ssl=true
2019-12-07T12:14:39.630-0600 I  NETWORK  [js] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-00-gjc2u.mongodb:27017,cluster0-shard-00-01-gjc2u.mongodb:27017,cluster0-shard-00-02-gjc2u.mongodb:27017
2019-12-07T12:14:39.630-0600 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-gjc2u.mongodb:27017
2019-12-07T12:14:39.631-0600 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-gjc2u.mongodb:27017
2019-12-07T12:14:39.631-0600 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-gjc2u.mongodb:27017
2019-12-07T12:14:40.259-0600 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Confirmed replica set for Cluster0-shard-0 is Cluster0-shard-0/cluster0-shard-00-00-gjc2u.mongodb:27017,cluster0-shard-00-01-gjc2u.mongodb:27017,cluster0-shard-00-02-gjc2u.mongodb:27017
2019-12-07T12:14:40.799-0600 I  NETWORK  [js] Marking host cluster0-shard-00-00-gjc2u.mongodb:27017 as failed :: caused by :: Location40659: can't connect to new replica set master [cluster0-shard-00-00-gjc2u.mongodb:27017], err: AuthenticationFailed: bad auth Authentication failed.


*** It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.


2019-12-07T12:14:40.800-0600 E  QUERY    [js] Error: can't connect to new replica set master [cluster0-shard-00-00-gjc2u.mongodb:27017], err: AuthenticationFailed: bad auth Authentication failed. :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2019-12-07T12:14:40.803-0600 F  -        [main] exception: connect failed
2019-12-07T12:14:40.804-0600 E  -        [main] exiting with code 1

I have whitelisted my IP address and made sure everything is in order. What could be causing this problem and how could I fix it? Why would this problem be occurring?

Trying to set up MongoDB for my Node.JS application. I running this mand:

mongo "mongodb+srv://cluster0-gjc2u.mongodb/test"  --username <myusername>

And getting this response every single time.

MongoDB shell version v4.2.1
Enter password:
connecting to: mongodb://cluster0-shard-00-00-gjc2u.mongodb:27017,cluster0-shard-00-01-gjc2u.mongodb:27017,cluster0-shard-00-02-gjc2u.mongodb:27017/test?authSource=admin&pressors=disabled&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0&ssl=true
2019-12-07T12:14:39.630-0600 I  NETWORK  [js] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-00-gjc2u.mongodb:27017,cluster0-shard-00-01-gjc2u.mongodb:27017,cluster0-shard-00-02-gjc2u.mongodb:27017
2019-12-07T12:14:39.630-0600 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-gjc2u.mongodb:27017
2019-12-07T12:14:39.631-0600 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-gjc2u.mongodb:27017
2019-12-07T12:14:39.631-0600 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-gjc2u.mongodb:27017
2019-12-07T12:14:40.259-0600 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Confirmed replica set for Cluster0-shard-0 is Cluster0-shard-0/cluster0-shard-00-00-gjc2u.mongodb:27017,cluster0-shard-00-01-gjc2u.mongodb:27017,cluster0-shard-00-02-gjc2u.mongodb:27017
2019-12-07T12:14:40.799-0600 I  NETWORK  [js] Marking host cluster0-shard-00-00-gjc2u.mongodb:27017 as failed :: caused by :: Location40659: can't connect to new replica set master [cluster0-shard-00-00-gjc2u.mongodb:27017], err: AuthenticationFailed: bad auth Authentication failed.


*** It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.


2019-12-07T12:14:40.800-0600 E  QUERY    [js] Error: can't connect to new replica set master [cluster0-shard-00-00-gjc2u.mongodb:27017], err: AuthenticationFailed: bad auth Authentication failed. :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2019-12-07T12:14:40.803-0600 F  -        [main] exception: connect failed
2019-12-07T12:14:40.804-0600 E  -        [main] exiting with code 1

I have whitelisted my IP address and made sure everything is in order. What could be causing this problem and how could I fix it? Why would this problem be occurring?

Share Improve this question asked Dec 7, 2019 at 18:22 Andrew YoungAndrew Young 7442 gold badges14 silver badges25 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 3

What I tried was:

  1. Create new user
  2. Made sure the username and password for my mongoURI when connecting my application is the same as the username and password for when I connect with the mongo shell.
  3. Run your connection string in your mand line in your application.

I realise that "just wait a bit" isn't a terribly constructive answer, but I had the same issue and no luck in finding a solution, so left it for a couple hours and came back to find it working perfectly.

The text that says your change has been deployed is misleading. Not sure why it takes several hours to kick in, but for reference I found this when using the M0 Sandbox cluster tier.

So you have to take care of 2 things.

1) First off, having mongodb in your $PATH, create a .bash_profile under the home folder if you don't have it already, then insert the following.(For Ubuntu)

export PATH="$PATH:/usr/bin/mongo" Make sure you place the location of mongo on your puter. If you don't know the location, type whereis mongo on the terminal. After saving, type source ~/.bashrc in the terminal.

2) Lastly, copy the connect link from the mongodb atlas, and when asked for username and password

please provide the credentials set to access the database not the mongdb atlas account.

This resolution might be specific for the mLabs to MongoDB Atlas migration tool provided by Cloud MongoDB.

My resolution was to:

  1. Re-create the user with the same user name
  2. Change from spesific mLabs grants to Atlas built-in roles
  3. Set new credentials, I also avoided using special chars.

Good luck!

Create a simple password which doesn't have any special characters, it only includes alphabets and numbers.

I wasn't able to access but changing password worked for me.

本文标签: javascriptMongoDB Can39t connect to new replica set masterStack Overflow