1. First modify the configuration file of mongodb to let it listen to all external network IPs; edit the file: /etc/mongodb.conf
The modified content is as follows:
bind_ip = 0.0.0.0 port = 27017 auth=true
2. Then modify the file: /etc/mongod.conf
Modify as follows:
bind_ip = 0.0.0.0 port = 27017
3. Restart mongodb.
code show as below:
/etc/init.d/mongodb restart
4. Add access rights to the user.
code show as below:
db.createUser( { user: "<username>", pwd: "<password>", roles: [ "readWrite", "dbAdmin" ] } )
<username>: Username.
<password>: Password.
Test if this user can access:
db.auth('username','password')
Delete a user:
db.removeUser('username')
5. Link, the code is as follows:
mongo remote_server_ip:27017/mongodb_name -u "<username>" -p "<password>"
Note: The above code mongodb must be installed globally, otherwise it must be:
<mongodb_address>/mongo remote_server_ip:27017/mongodb_name -u "<username>" -p "<password>"
<mongodb_address>: represents the installation address of the database.
Since port 27017 is used, this port must be opened if the firewall is enabled. For details on opening the port, see:
http://975156298.iteye.com/blog/2323688