Static IP guide
Connecting to MongoDB with a static IP from a Node app on Heroku
MongoDB Atlas rejects connections from addresses outside its IP Access List, and adding 0.0.0.0/0 to make Heroku work defeats the point of the list. The MongoDB Node.js driver has native SOCKS proxy support, so Mongoose can route through Fixie Socks with four extra connection options and no tunnel process.
Recommended setup
Use Fixie Socks Heroku add-on for MongoDB connections from a deployment environment with changing outbound IPs. Store the proxy value in FIXIE_SOCKS_HOST, then configure Node.js to route outbound traffic through Fixie before connecting to MongoDB.
Set up Fixie on Heroku
Heroku is a native Fixie marketplace flow. Install the Fixie Socks Heroku add-on or attach it from the Heroku CLI. Heroku will create FIXIE_SOCKS_HOST as a config var for the app.
Attach fixie-socks to your Heroku app
heroku addons:create fixie-socks
heroku config:get FIXIE_SOCKS_HOSTImplementation
The example below shows the core application-side change. Keep credentials in environment variables and avoid committing proxy, database, or API secrets.
Connect to MongoDB through FIXIE_SOCKS_HOST
const mongoose = require('mongoose');
const fixieValues = process.env.FIXIE_SOCKS_HOST.split(new RegExp('[/(:\\/@)/]+'));
mongoose.connect(process.env.MONGODB_URI, {
proxyUsername: fixieValues[0],
proxyPassword: fixieValues[1],
proxyHost: fixieValues[2],
proxyPort: Number(fixieValues[3]),
}).then(() => {
console.log('Connected to MongoDB');
});Good to know
- Add both Fixie IPs to Atlas under Network Access → IP Access List, then remove any broad CIDR entries you added as a workaround.
- The proxy options work with standard and mongodb+srv connection strings alike; SRV resolution happens over DNS before the proxied TCP connection is opened.
- Native driver SOCKS support arrived in the 4.x series — if you are pinned to an old 3.x driver, upgrade before wiring in the proxy options.
Allowlist and test the static IPs
- Open the Fixie dashboard and copy the outbound IP addresses for this proxy.
- Add both IPs to the MongoDB network access list.
- Deploy the updated Node.js app on Heroku.
- Run a small connection test before sending production traffic.
Related guides
- Making API requests with a static IP from a Node app on Heroku
- Connecting to MongoDB with a static IP from a Node app on Vercel
- Connecting to Postgres with a static IP from a Node app on Heroku
- Connecting to MongoDB with a static IP from a Node app on Render
- Connecting to MySQL with a static IP from a Node app on Heroku
- Connecting to Amazon Redshift with a static IP from a Node app on Heroku