1
votes

I have:

  1. MongoDB Atlas Cluster

  2. VPC Peering between GCP.

When I tried connect to DB from my home laptop:

mongo "mongodb+srv://hello-dev-x53pa.gcp.mongodb.net/test" --username myuser

I received an error:

2020-01-09T15:32:33.697+0200 W NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Failed to connect to 192.168.240.4:27017 after 5000ms milliseconds, giving up.
2020-01-09T15:32:33.698+0200 W NETWORK  [thread1] Failed to connect to 192.168.240.2:27017 after 5000ms milliseconds, giving up.

I see that received local IP address but I don't understand how I can connect to the my DB which in the private VPC?

I will be very happy for any help!

1

1 Answers

0
votes

You have to whitelist your IP address. VPC Peering allowed GCP resources to connect to your database, but you also need to specify your private IP address.

Refer to below document to add IP address:

https://docs.atlas.mongodb.com/security-whitelist/#add-whitelist-entries

EDIT: I wouldn't whitelist all IP addresses, just use the "current IP address" option to white list the IP address your laptop is trying to access from.

Also, try adding --password option, as this should be used in conjunction with --username option. Also, confirm that "test" db is where you created the username/password.

mongo "mongodb+srv://hello-dev-x53pa.gcp.mongodb.net/test" --username myuser --password mypassword