MongoDB opens network access

By default, MongoDB can only be accessed from the local machine and does not require a password.
However, in a production environment, the server and development machine are generally not the same machine.
At this time, you need to create a database user to enable permission to access from the network.
Please see example:

use test //Switch to the test database

//Create a tony user, the password is password1, and the permission is readWrite
db.createUser( { user: "tony", pwd: "password1", roles: [ { role: "readWrite", db: "test" } ]})


If you want to see what other permissions are available, use the following:
use test
show roles


In this way, the database can be accessed from the network through coding.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326219433&siteId=291194637