First, I need to delete the previously created Service tat.
SC Delete "MongoDB"
Re-create the service and add the -- auth Parameter
D: \ MongoDB> mongod -- dbpath D: \ MongoDB \ data -- logpath D: \ MongoDB \ log \ MongoDB. log -- logappend -- servicename MongoDB -- auth -- install
All output going to: D: \ MongoDB \ log \ MongoDB. Log
Creating service MongoDB.
Service creation successful.
Service can be started from the command line via 'net start "MongoDB "'.
When you start Mongo again, the system will prompt that you do not have the permission.
> Show users
Wed Aug 17 09:53:30 uncaught exception: Error :{
"$ Err": "unauthorized DB: Admin lock type:-1 client: 127.0.0.1 ",
"Code": 10057
}
You can log in with the-u-p Parameter-> Mongo [database name]-U [user name]-P
D: \ MongoDB> Mongo admin-u admin-P
MongoDB shell version: 1.8.2
Enter password:
Connecting to: Admin
Of course. Do not forget to create a user first. The user in the admin database is global.
Use [database]
DB. adduser ('admin', 'pwd ')
Show users
To create a read-only user:
DB. adduser ('rousr', 'pwd', true)
Here is the security verification in C:
Link string format: MongoDB: // [Username: password @] hostname [: Port] [/[database] [? Options]
You just need to change the link string of the previous example to "MongoDB: // uname: Pwd @ localhost ".
... My previous password contains @, so... Tat
Changing the password is the same as creating a USER command.
DB. adduser ('admin', 'newpwd ')
For other Common commands, click "-".
Common commands
Http://hi.baidu.com/pappercut/blog/item/4fc5281fd2873ed2a7866997.html