Reputation: 6901
I'm new to mongoDB and like it so far, I work local for my dev where I have mongo running as service on Win7. I have it allso running as a service on my VPS on Win server 2008. When I am on the server it works fine but I don't know hos to set it up so I can acces it from outside of the server? Can't find any good documentation on that. Also, I'm having hard time to do backup/restore on the server from my local computer since I can't see it from outside of the server.
I would like to have more information also on the master/slave and hos to set this up properly.
When I run netstat -anb I get
TCP 127.0.0.1:27017 0.0.0.0:0 LISTENING
[mongod.exe]
TCP 127.0.0.1:27017 127.0.0.1:62990 ESTABLISHED
[mongod.exe]
TCP 127.0.0.1:28017 0.0.0.0:0 LISTENING
That's all I have for mongod.exe
[Edit]
I tried to reinstall with --bind_ip xxx.x.x.xx and now the xxx.x.x.xx:27017 works but only on the remote server, if I try to access from anywhere it fails.
Also, I turned off the firewall and it does not change anything.
Thanks a lot!
Upvotes: 12
Views: 19388
Reputation: 1715
In the mongod.cfg (at C:\Program Files\MongoDB\Server\4.0\bin), just update:
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1
bindIp: 0.0.0.0
Then restart the MongoDB Server service
let the mongo db bing to 0.0.0.0 i.e. all interfaces and not only 127.0.0.1. Then it will allow connections to all interfaces.
Upvotes: 7
Reputation: 1026
Install mongo and setup
Install mongodb with windows service checked
Allow specific port in firewall: 27017
In the mongod.cfg (at C:\Program Files\MongoDB\Server\4.4\bin), just comment bindIp: 127.0.0.1 and add new line bindIp: 0.0.0.0:
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1
bindIp: 0.0.0.0
Last two steps will allow you remote access
create user
Open cmd go to path of installation, for example C:\Program Files\MongoDB\Server\4.4\bin
in cmd type mongo C:\Program Files\MongoDB\Server\4.4\bin>mongo
then type use admin (admin is database) and at the end
db.createUser( { user: "adminName", pwd: "xxxxxx", roles: ["readWrite"] })
restart mongo service in services
Upvotes: 1
Reputation: 33437
For MongoDb 4.x I did the following things:
By default MongoDb is installed on C:\Program Files\MongoDB\Server\4.0\bin
in Windows and it contains a file called mongod.cfg
.
bindIp: 127.0.0.1
and added host ip bindIp: 127.0.0.1, 192.168.1.xxx
Restart MongoDb service and you should be able to access it from another computer 192.168.1.xxx:27017
.
Upvotes: 1
Reputation: 1713
some details can be refer to this article http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-install-mongodb-windows-server/
Upvotes: 0
Reputation: 6508
I think I found how to achieve it. First of all, allow the port 27017 on your firewall. Then I installed Mongo as a service using a configuration file. I created the mongos.conf like this:
dbpath = d:\mongo\data
logpath = d:\mongo\logs
noauth = true # use 'true' for options that don't take an argument
I saved it under: d:\mongo\mongos.conf
Then I did this in the command line:
mongod --config d:\mongo\mongos.conf --reinstall
The key is to make sure there is no bind_ip config key in your configuration file. So it will allow mongo to be binded to any ip. You should then be able to go to
http://localhost:27017 and see the following message:
You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number
And you should also be able to go to:
http://192.168.x.x:27017 (your ip) and you should see the same output.
Upvotes: 13
Reputation: 41902
Try running this command from an admin DOS prompt to open external access to the default MongoDB port 27017:
C:\> netsh.exe advfirewall firewall add rule name="MongoDB (port 27017)"
dir=in action=allow protocol=TCP localport=27017
Upvotes: 4
Reputation: 14978
If you can't access it remotely it sounds like a firewall issue. By default mongod listens on port 27017. Is that port accessible from the machine you are trying to connect from? This sounds like more or a firewall issue than an issue with mongod. Can you edit your question to provice the command line the mongo service runs as.
A good source for information on replica sets in this article on Kristina Chodorow's blog.
Upvotes: 1