Reputation: 388
I've having issues accessing MongoDB Atlas from Google Cloud functions. It is giving me error regarding IP Whitelisting but I've added both (Serverless VPC Access) IP address range and VPC Network Peering IP address range to MongoDB whitelist.
I've also created MongoDB peering with google cloud.
If I allow (access from anywhere) then my mongodb starts working fine, otherwise it gives error regarding IP whitelisting.
I'm not sure what else I should add to MongoDB whitelist when I've added both IP's already.
Can anyone help me regarding this? A simple step by step guide will mean a lot. (images/video can help big if possible)
**Edit
I took (Atlas GCP Project ID & Atlas VPC Name) to create (VPC Network Peering). And they both are (Active & Available).
And after that I created (Serverless VPC Access).
And added it to my function inside (connection), a function that will connect to mongoDB to get data. It works fine if I set mongoDB to (allow from everywhere) but do not work without it.
And after that I added all 3 IP's/CIDR blocks to the IP Whitelist.
But I've still confused that when I run this function it still gives me error about IP Whitelist and only works if I allow traffic from everywhere in mongoDB.
Don't know what I'm doing right and what I'm doing wrong. As there aren't any videos available on internet to achieve this.
I even tried this article but still nothing works out.
This is the error I'm getting.
Upvotes: 0
Views: 1176
Reputation: 400
I encountered the same issue, and ultimately discovered that I needed to use a private connection string rather than a standard one.
from the official documentation:
You must add your VPC CIDR block address (or subset) associated with the peer VPC to the IP access list before your new VPC peer can connect to your Atlas cluster. When connecting to your cluster, you must use the new private connection strings to utilize the peering.
https://www.mongodb.com/docs/atlas/security-vpc-peering/
Private connection strings examples:
mongodb://xyx456-shard-00-00-pri.ab123.mongodb.net:27017
mongodb+srv://xyx456-pri.ab123.mongodb.net
Upvotes: 0
Reputation: 14490
If you know you need to whitelist specific IPs:
Verify this IP is in your expected range, etc.
If you know you don't need to whitelist specific IPs:
If you don't know whether specific IPs need to be waitlisted:
Upvotes: 1