9 months ago
I'm currently having trouble getting MongoDB to connect on a private network. It works fine when I use a public network, but private access seems blocked. I already have another project running on a private network without any issues, so I'm wondering:
Are there any restrictions on the Hobby plan that would prevent private network access?
Or could this be an issue on your
end?
1 Replies
9 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open brody • 9 months ago
9 months ago
afaik there are no explicit documentation or anyone reporting that the Hobby or any plan restricts private network access. You have to use ipv6 family for your MongoDB service and any service that needs to connect to it, since private networking only happens in that. Then, use the private networking environment variables (e.g., MONGO_PRIVATE_URL or similar). I am saying this specifically because one time i also faced a similar issue, where my mongodb service were listening on ipv4 family and i was trying to connect to it using ipv6.
For example have something like this.
.env
# IP VERSION (ipv4 or ipv6)
IP_VERSION=ipv4db.js
mongoose.connect(this.uri, {
autoIndex: true,
maxPoolSize: 5,
serverSelectionTimeoutMS: 5000,
socketTimeoutMS: 45000,
heartbeatFrequencyMS: 10000,
family: this.uri.includes("localhost") || this.uri.includes("127.0.0.1") ? 4 : 6
});express-server.js
const startServer = async () => {
try {
await dbConnection.connect();
const bind_address = IP_VERSION === "ipv4" ? "0.0.0.0" : "::";
console.log("bind_address -> ", bind_address);
server = app.listen(variables.PORT, bind_address, () => {
console.log(`🚀 Express seraver running on ${bind_address} port ${PORT}`);
});
["SIGTERM", "SIGINT", "SIGUSR2"].forEach((signal) => {
process.on(signal, () => gracefulShutdown(signal));
});
} catch (error) {
console.error("Failed to start server:: ", error.message);
process.exit(1);
}
};