Connect to MongoDB Atlas
Lock MongoDB Atlas Network Access down to a single /32 instead of 0.0.0.0/0 while connecting from serverless apps, CI runners, or laptops.
First payment refunded within 7 days if it doesn’t work for you
- MongoDB Atlas
On this page12
MongoDB Atlas rejects every connection whose source IP is missing from your project’s Network Access list. Prontaro gives you two TCP options: driver-level SOCKS5 (socks5h://) with no CLI installation, or prontaro forward for mongosh, mongodump, and clients that do not support SOCKS5.
Why an HTTP proxy does not work with MongoDB
MongoDB drivers speak a binary TCP protocol on port 27017, not HTTP. Setting HTTP_PROXY or passing an http:// proxy URL will not route database connections.
Choose one of two TCP paths:
| Method | Best for | Replica set & SRV handling |
|---|---|---|
Driver SOCKS5 (socks5h://) |
Node.js (mongodb, Mongoose), serverless (Vercel, AWS Lambda), containers |
Supports mongodb+srv:// discovery and automatic primary failover |
prontaro forward |
Local dev, mongosh, mongodump, Prisma, Python pymongo |
Maps one local TCP port to one Atlas shard host at a time |
Prerequisites
- A Prontaro account on Dedicated or Pro (plans). Open my.prontaro.com/ips, choose the location closest to your Atlas cluster, and click Add IP.
- A MongoDB Atlas cluster with a database user configured.
- You do not need
prontaro CLIfor Option A (SOCKS5 in your driver) — create proxy credentials in the dashboard. The CLI is only required for Option B (prontaro forward).
Step 1. Allowlist your static IP in MongoDB Atlas
Network Access is configured at the Project level (not Organization). Open your project in MongoDB Atlas and add your IPv4 with a /32 mask:
- Access List Entry
- 203.0.113.10/32
- Comment
- prontaro-atlas-prod
Click Confirm and wait for the status badge to change from Pending to Active. Remove any temporary 0.0.0.0/0 rule after verifying connectivity in Step 4.
Step 2. Create proxy credentials
- Open IP addresses in my.prontaro.com, select your IP, and click Create proxy credentials (for example,
atlas-prod). - Copy the
SOCKS5URL (socks5h://u_atlas:s3cr3t@<entry>.prontaro.io:1080).
Leave the To destination list unrestricted until Step 5 so you can verify your exit IP with api.ipify.org in Step 4.
Step 3. Connect through your static IP
Option A. Node.js (mongodb and Mongoose) over SOCKS5
The official Node.js mongodb driver (v6+) supports SOCKS5 via the optional socks package and sends hostnames to the proxy (socks5h), so mongodb+srv:// and primary failover work out of the box.
Install the driver with socks:
npm install mongodb socksCreate a one-off verification script atlas-check.mjs (in a server or Lambda, instantiate MongoClient once at startup and do not call client.close() on every request):
// atlas-check.mjs — one-off verification script
import { MongoClient } from 'mongodb';
const mongoUri = process.env.MONGODB_URI;
const socksUrl = process.env.PRONTARO_SOCKS_URL;
if (!mongoUri || !socksUrl) {
throw new Error('Set MONGODB_URI and PRONTARO_SOCKS_URL in your environment');
}
const proxy = new URL(socksUrl);
const client = new MongoClient(mongoUri, {
proxyHost: proxy.hostname,
proxyPort: Number(proxy.port),
proxyUsername: decodeURIComponent(proxy.username),
proxyPassword: decodeURIComponent(proxy.password),
maxPoolSize: 10,
serverSelectionTimeoutMS: 10_000,
});
try {
await client.connect();
const result = await client.db('admin').command({ ping: 1 });
console.log('Atlas ping:', result);
} finally {
await client.close();
}- Mongoose: install
socksand pass the sameproxyHost,proxyPort,proxyUsername, andproxyPasswordoptions tomongoose.connect(mongoUri, { ... }). - Prisma and Python
pymongo: neither supports SOCKS5 out of the box — use Option B (prontaro forward), orPySocksforpymongo.
Option B. Local TCP forwarding with prontaro forward (mongosh, mongodump, Prisma, pymongo)
When a tool or driver does not support SOCKS5, bind a local TCP port on 127.0.0.1:
- Find one of your Atlas shard hostnames (from Connect → Drivers or
dig):
dig +short SRV _mongodb._tcp.cluster0.example.mongodb.net- Start the forwarder to that shard host:
prontaro forward 27018 cluster0-shard-00-00.example.mongodb.net:27017 --ip 203.0.113.10prontaro forward 27018 cluster0-shard-00-00.example.mongodb.net:27017
127.0.0.1:27018 → cluster0-shard-00-00.example.mongodb.net:27017 from your IP 203.0.113.10- Connect with
mongoshormongodump. Atlas enforces TLS hostname verification against*.example.mongodb.net, so connecting directly to127.0.0.1:27018fails validation.
On a workstation with sudo, temporarily map 127.0.0.1 cluster0-shard-00-00.example.mongodb.net in /etc/hosts, then connect by hostname:
mongosh "mongodb://cluster0-shard-00-00.example.mongodb.net:27018/app?tls=true&directConnection=true&authSource=admin" \
--username "$ATLAS_USER"For mongodump, pass the same URI via --uri:
mongodump --uri="mongodb://${ATLAS_USER}:${ATLAS_PASS}@cluster0-shard-00-00.example.mongodb.net:27018/app?tls=true&directConnection=true&authSource=admin"Step 4. Verify the exit IP and Atlas connection
First confirm the SOCKS5 route exits from your dedicated IPv4:
export PRONTARO_SOCKS_URL="socks5h://u_atlas:s3cr3t@<entry>.prontaro.io:1080"
curl -fsS --proxy "$PRONTARO_SOCKS_URL" https://api.ipify.org
203.0.113.10Then run the Atlas ping script:
export MONGODB_URI="mongodb+srv://app_user:db_pass@cluster0.example.mongodb.net/app?retryWrites=true&w=majority"
node atlas-check.mjs
Atlas ping: { ok: 1 }Once ping succeeds, delete any temporary 0.0.0.0/0 entry from Atlas Network Access.
Step 5. Lock down allowed targets (recommended)
Now restrict your proxy credentials to MongoDB Atlas hosts on port 27017:
- Open IP addresses → Proxy credentials in my.prontaro.com, select
atlas-prod, and switch to Access. - Add
*.mongodb.net:27017under To and save.
Limits and notes
- Single-host forwarding and primary failover. One
prontaro forwardtargets one shard (directConnection=true). If Atlas elects a new primary, writes fail until you re-forward it. Use driver SOCKS5 in production. - Keep serverless pools small. Set
maxPoolSizeto5–10and reuseMongoClientacross invocations to stay within your concurrent connection limit. - Match regions. Place your Prontaro IP near your Atlas cluster to keep latency low when your app runs many small queries.
- BGP failover keeps your IP unchanged. BGP failover moves your
/32automatically without changing the Atlas allowlist, and drivers withretryWrites=truereconnect on their own.
Common errors
| Error | Cause | Fix |
|---|---|---|
MongoServerSelectionError: Server selection timed out |
Dedicated IP is still Pending in Atlas Network Access, or wrong IP was entered. |
Confirm <your-IP>/32 is Active under Project → Security → Network Access. |
Hostname/IP does not match certificate's altnames |
Connected mongosh to 127.0.0.1:27018 over prontaro forward without matching TLS SNI. |
Map the shard hostname to 127.0.0.1 in /etc/hosts for the session, or switch to driver SOCKS5. |
| Proxy blocks Atlas after Step 5 | Client resolved DNS locally (socks5:// without h) instead of passing the hostname. |
Switch to socks5h:// and verify *.mongodb.net:27017 is in the To list. |
For 407, 403, and general proxy issues, see error codes and HTTP & SOCKS5 proxy.
Next steps
- Static IP for Vercel — configure outbound proxy routing for Vercel Functions.
- Static IP for AWS Lambda — connect from Lambda to allowlisted services without a NAT Gateway.
- Local port forwarding (
prontaro forward) — full reference for outbound TCP forwarding and TLS verification. - HTTP & SOCKS5 proxy — proxy credentials, target allowlists, and password rotation.
Related guides
- Local port forwarding (prontaro forward)Connect database drivers, SFTP clients, and CLI tools to remote servers from your static IPv4 over a local TCP port — no proxy support needed.
- HTTP & SOCKS5 proxyRoute outbound HTTP, HTTPS, and TCP connections through your static IPv4 with one proxy credential set, end-to-end TLS, and From/To rules.
- Static IP for VercelSend outbound requests from Vercel Functions and Edge Runtime through one dedicated IPv4 to pass payment gateway, API, and database allowlists.
- Static IP for AWS LambdaGive AWS Lambda a dedicated static IPv4 without VPC plumbing or NAT Gateway fees using HTTPS proxy, SOCKS5, or a Relay URL.
Something wrong on this page? Contact us