To find all posts about MongoDB, click on the MongoDB category at the bottom of this post to find all posts tagged with that keyword.
So far, I have been working with MongoDB on a Windows instance. I have instances on my local Windows 8.1 workstation, and Windows Server 2012 on Azure. To test the firewall settings though, I brought up an instance on one of my local Windows 2012 servers.
From everything I gathered, I put together this script file, to enable to the correct ports in a Windows firewall:
@echo off REM ** Optional - to reset to defaults REM echo Resetting firewall rules... REM netsh advfirewall reset echo Adding MongoD port 27017 netsh advfirewall firewall add rule name="Open mongod port 27017" dir=in action=allow protocol=TCP localport=27017 echo Adding MongoD shared port 27017 netsh advfirewall firewall add rule name="Open mongod shard port 27017" dir=in action=allow protocol=TCP localport=27017 echo Adding MongoD program through the firewall netsh advfirewall firewall add rule name="Allowing mongod" dir=in action=allow program=" C:mongodbbinmongod.exe" echo Adding MongoS program through the firewall netsh advfirewall firewall add rule name="Allowing mongos" dir=in action=allow program=" C:mongodbbinmongos.exe" echo Done. pause
On my local server instance, it worked great! I could use mongo.exe on my workstation and connect to the instance on my local server. Whereas, I couldn’t before I made that change.
The bad news is that when I tried this on the Azure VM – I got no errors and everything looked OK, but I still can’t connect to it from my local machine. I remember Azure having another layer of security where only certain external IP addresses could access certain resources. However, Azure has changed so much (and continues to change so much) that I can’t figure out where to fix that in the Azure console.
So, in my Azure VM, I have opened up the firewall on that server – but an Azure-hosted app, nor my local machine can connect. I’m at a dead-end with that.
Aside from that though, the script above should work for opening the Windows firewall so that other machines can connect to your instance.