Skip to content

Instantly share code, notes, and snippets.

@thanhpcc96
Last active June 12, 2019 10:22
Show Gist options
  • Select an option

  • Save thanhpcc96/cb35e2392be2c684efb50c9cb72c2b0a to your computer and use it in GitHub Desktop.

Select an option

Save thanhpcc96/cb35e2392be2c684efb50c9cb72c2b0a to your computer and use it in GitHub Desktop.
Remote MongoDB

1. Set up your user

  • access to mongo
mongo
  • create database
user database_name
  • create user
db.createUser({
    user: 'your_user_name',
    pwd: 'secretPassword',
    roles: [{ role: 'readWrite', db:'database_name'}]
})

2. Edit Config /etc/mongod.conf

sudo nano /etc/mongod.conf
  • then edit net:
# network interfaces
net:
  port: 27017 <- you can change port
  bindIp: 0.0.0.0  <- change from 127.0.0.1 to 0.0.0.0 for remote access
  • then find security
security:
  authorization: 'enabled'
  • Save

Restart mongo service

sudo service mongod restart
  • you can watch log to confirm mongo service restart successfully
sudo tail -f /var/log/mongodb/mongod.log

Test Connection from your Pc to Remote server

  • terminal
mongo -u your_user_name -p secretPassword 123.45.67.89/database_name

replace your_user_name and secretPassword and database_name youself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment