Setting mongodb for remote access
Created at 2018-01-30 Updated at 2024-11-07 - 2 min. read
Setting up mongodb on remote system with remote access.
Install the mongo database from here.
I am using ubuntu 16.04. Check if its running or not.
sudo service mongod status
.- Try to connect it over locally by running command
mongo
create a user and assign him the role userAdminAnyDatabase
1
2
3
4
5
6
7
8
9
10
11
12
13
14use admin
var user = {
"user" : "admin",
"pwd" : "manager",
roles : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
db.createUser(user);
exitConnect with the Admnistrator user
1
mongo admin -u admin -p manager
Create Application User for test database
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16mongo admin -u admin -p manager
use test
var user = {
"user" : "website",
"pwd" : "abc123",
roles : [
{
"role" : "readWrite",
"db" : "test"
}
]
}
db.createUser(user);
exitMake your mongo accessible from remote
Open the mongo config filesudo nano /etc/mongod.conf
Change the following in the above file
1
2
3
4# network interfaces
net:
port: 27017
bindIp: 0.0.0.0 <- change thisSet authentication on your mongo.
1
sudo nano /etc/mongod.conf
Add the following line at the end of file
1
2security:
authorization: enabledRestart the service
1
sudo service mongod restart
Now you could easily connect to mongo from remote using the username and password you created.