1
votes

I followed this guide to set up a VPC to allow traffic from my GCP project to my MongoDB Atlas database.

  1. Set up VPC on Atlas

enter image description here

  1. Whitelist personal computer and GCP

enter image description here

  1. Create VPC on GCP

enter image description here

  1. Test locally

Works

  1. Setup a VM

enter image description here

  1. SSH onto VM and test logging in:
...

2020-04-01T04:15:59.926+0000 I NETWORK  [js] DBClientConnection failed to receive message from shard...mongodb.net.:27017 - HostUnreachable: Connection closed by peer
    2020-04-01T04:15:59.927+0000 W NETWORK  [js] Unable to reach primary for set shard...
*** It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.


    2020-04-01T04:15:59.927+0000 E QUERY    [js] Error: connect failed to replica set shard.../shard...mongodb.net.:27017,shard...mongodb.net.:27017,shard...mongodb.net.:27017 :
    connect@src/mongo/shell/mongo.js:344:17
    @(connect):2:6
    exception: connect failed
2

2 Answers

1
votes

You must have a M10 cluster or above.

-1
votes

Please follow the official documentation https://docs.atlas.mongodb.com/security-vpc-peering/index.html

  1. Make sure that the CIDR range of your GCP private network should not overlap with the Atlas CIDR because in that case also the VPC Peering will not work.

  2. However, if it is urgent , then you can whitelist your public IP in Atlas and get it working.

To make it running Please add the screenshots of your GCP console with the CIDR Ranges, Security groups , Routetables .