Ajmani
Ajmani

Reputation: 43

How to access mongodb remotely in linux

I have successfully installed mongodb into my linux machine.

Please suggest how to access it remotely.

Upvotes: 0

Views: 14569

Answers (1)

Ajmani
Ajmani

Reputation: 43

I worked on it and searched for it. Finally came up with following solution.

  1. Importing the Public Key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
  1. Creating a List File
echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
  1. Installing and Verifying MongoDB
sudo apt-get install -y mongodb-org
service mongod status
  1. Creating a user
use admin 
db.createUser({user:"<username>", pwd:"<password>", roles:[{role:"root", db:"admin"}]})
  1. Try to Login
mongo -u <username> -p <password> --authenticationDatabase admin
  1. Set vi /etc/mongod.conf
# Comment bindIp with #
service mongod restart
  1. Allow connections on port 27017, MongoDB default port
ufw allow 27017
ufw status
  1. Enable mongodb authentication on vi /etc/mongod.conf
security: 
    authorization: enabled
  1. To access mongodb remotely the command is:
mongo -u <username> -p <password> <ip-address>:27017/<collection-name>

Upvotes: 2

Related Questions