Management of MongoDB

Source: Internet
Author: User

User management:

Add Users and give permissions

Db.createuser ({User: "Hy", pwd: "123", Roles:[{role: "Useradmin", DB: "Test"}]})

The 3.4 version of the MongoDB configuration file /etc/mongod.conf is, in the format Yaml. Click to view official documents

Turn on user authentication

Click to view the official guide
1. Add Users
Start MongoDB:

mongod

Start the MongoDB shell

mongo

Add Users:

use admindb.createUser(  {    user: "myUserAdmin", pwd: "abc123", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] })

2. Change the configuration file

In the configuration file, you will

#security:

In the # minus, and on its next line, empty two spaces, plus authorization: enabled , as follows

security:  authorization: enabled

Note: authorization: enabled Add a space after the colon, which is required by the YAML syntax

3. Restart the MongoDB database

sudo service mongod restart

Note: The command is mongod , notmongodb

Setting up remote connections

Note: The old version of the GUI management software may not support the new version of the database, please ensure that the software is available before testing

In the configuration file, you will

bindIp: 127.0.0.1

Comment out (that is, the first addition to the sentence # )

#bindIp: 127.0.0.1

Restart database

sudo service mongod restart
Change Data Catalog

The default data store directory is /var/lib/mongodb , assuming our destination path is/home/mongodb

Close the database

sudo service mongod stop

Set the item to the destination path in the configuration file storage.dbPath , as modified below

storage:  dbPath: /home/mongodb

Copy the files from the original directory to the new directory:

/var/bin/mongodb/* /home/mongodb/

To mongod.lock start a database after deleting a file

sudo rm /home/mongodb/mongod.locksudo service mongod start

Testing remote connections

Attention:

When your mongo command error occurs, when the connection fails, try deleting the file in the Datastore directory and restart the mongod.lock MongoDB database

Management of MongoDB

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.