After mongodb is installed, there is no administrator. If you want to set an administrator for mongodb, you need to start it with user authorization:
/Usr/local/webserver/mongodb/bin/mongod -- dbpath =/usr/local/webserver/mongodb/data -- logpath =/usr/local/webserver/mongodb/logs -- auth &
Log on to mongodb after startup
/Usr/local/webserver/mongodb/bin/mongo
Select admin database
Use admin
Add Super Administrator
Db. addUser ('root', 'root ');
Log in as a super administrator after exiting
/Usr/local/webserver/mongodb/bin/mongo-uroot-proot 192.168.1.106: 27017/admin
Next, we will add a database administrator. Take the test database as an example.
Use test
Db. addUser ('test', '123 ');
In this way, you can use/usr/local/webserver/mongodb/bin/mongo-utest-p1234 192.168.1.106: 27017/test
So that the test user can only access the test database.
Use PHP code to test:
$ M = new Mongo ("mongodb: // test: 1234@192.168.1.106: 27017/test ");
$ Db = $ m-> test; // select a database
$ C = $ db-> tb1; // sets in the ing database
// Query a piece of data by _ id
$ Data = $ c-> findOne (array ('_ id' => new consumer id ("50a8d6e5b21b7fabbf2bd97a ")));
Print_r ($ data );
Next, you need to pay the tax to install RockMongo for mongodb management. First, go to http://rock#.com/downloadsto download rockbench. The latest version is RockMongo v1.1.5. This version requires PHP extension version> = 1.3.0. There is nothing to say about the installation process. Decompress the package and place the file to the web server directory or subdirectory. Modify the following code in the config. php configuration file:
$ MONGO ["servers"] [$ I] ["server_name"] = "Server Name"; // write a memorable name.
$ MONGO ["servers"] [$ I] ["mongo_host"] = "server IP address"; // do not make a mistake
$ MONGO ["servers"] [$ I] ["cmd_auth"] = true; // Set it to true
After modification, you can access and enter the mongodb user name and password in the browser for management.