1. Pre-Connection preparation
This omits the operation installed on the server, which is the same process as the previous section.
To connect to a remote server, you first need to go to the remote server in the Bin folder under the MongoDB installation root directory (the default installation directory is C:\Program files\mongodb\server\4.0\bin) to find Mongod.cfg file, open
Find and change the value of Bindip to 127.0.0.1,0.0.0.0
Then go to Control Panel \ System and security \ Windows Firewall \ Advanced Settings \ Inbound rules \ New rule
Select port =>tcp=> specific local port number, enter, here I am using the default both 27017=> allow connection
At this point we can connect to the remote server locally and open the cmd input:
MONGO Host:port such as:
MONGO 122.22.22.222:27017
As you can see, you can already access MongoDB on the remote server.
2. Increase login Privileges
To access the remote server must be the authentication to log on or you can do it casually, this time in the remote server to connect to MongoDB (cmd input MONGO and then enter the use admin)
Next, we'll create an account that gives you super admin privileges.
Db.createuser ({User: "account", pwd: "Password", roles:[{"role": "Useradmin", "db": "admin"},{"role": "Root", "db": "admin"},{"role" ":" Useradminanydatabase "," db ":" Admin "}]})
Here to provide the corresponding permission name and explanation
READ: Allows the user to read the specified database
ReadWrite: Allows the user to read and write to the specified database
DbAdmin: Allows the user to perform administrative functions in the specified database, such as index creation, deletion, viewing statistics, or accessing System.profile
Useradmin: Allows the user to write to the System.users collection to create, delete, and manage users in the specified database
Clusteradmin: Available only in the admin database, giving the user administrative privileges on all shards and replica set related functions.
Readanydatabase: Only available in the Admin database, giving users read access to all databases
Readwriteanydatabase: Only available in the Admin database, giving users read and write access to all databases
Useradminanydatabase: Only available in the Admin database, giving the user useradmin permissions for all databases
Dbadminanydatabase: Only available in the Admin database, giving the user dbadmin permissions for all databases.
Root: Available only in the admin database. Super account, Super privilege
Then give the account authorization operation Db.auth ("account", "password")
The original service is non-auth verified, need to be deleted, (remember to exit MongoDB connection, enter exit return) in CMD execute SC delete MongoDB
To remove the win service and then stop the MongoDB service in service management, it will automatically refresh and not appear in the list.
Then install the service with auth verification, cmd input mongod.exe--dbpath C:\Program files\mongodb\server\4.0\data--logpath=c:\program files\ Mongodb\server\4.0\log\mongodb.log--logappend--auth--install
The path is set according to its own situation
We are visiting locally and entering show DBS will see the error message probably means no permission
This time we enter the account password connection in the local cmd
MONGO host:port/admin-u Account-p password
such as MONGO 122.22.22.222:2701/admin-u root-p ******
After successful login, enter show DBS to display correctly.
Warm hint, set the wrong password can execute this statement to modify Db.changeuserpassword (' account ',' password ');
[MongoDB]------WinDOS remote Server Deployment connection