mongodb remote link configuration

    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 =
port = 27017


    2. Then modify the file: /etc/mongod.conf

Modify as follows:

bind_ip =
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:

     user: "<username>",
     pwd: "<password>",
     roles: [ "readWrite", "dbAdmin" ]

  <username>: Username.

  <password>: Password.

Test if this user can access:


 Delete a user:



   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:






Guess you like