Mongodb adds user authorization and uses RockMongo for management

Source: Internet
Author: User
Tags mongodb php code

 

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.