The 6 Security Settings command for the MongoDB database _mongodb

Source: Internet
Author: User
Tags auth mongodb

1, the security certification mode to start

Copy Code code as follows:

Bin/mongod?–auth?-dbpath/users/mc2/mongo/db-logpath/users/mc2/mongo/log.log &

You can enable authentication mode by starting the Mongod process with the –auth option.

Alternatively, you can modify the/etc/mongodb.conf, set the auth=true, and restart the Mongod process.

2. Add User

Copy Code code as follows:

Db.adduser ("admin", "123456″")

3. Safety Certification

Copy Code code as follows:

Db.auth ("admin", "123456″")

In case of successful certification

Copy Code code as follows:

Db.system.users.find ()

{"_id": ObjectId ("5032e8386a7fc39e31978c50″"), "user": "admin", "readOnly": false, "pwd": "95ec4261124ba5951720b199908 D892b "}

otherwise return null

4. Write Data for database (sync to disk) lock

Copy Code code as follows:

Db.runcommand ({fsync:1,lock:1})

Description

This operation has been locked to the database and does not allow write data operations, which are generally useful when performing database backups. Execute the command, and the result example is as follows:

Copy Code code as follows:

Db.runcommand ({fsync:1,lock:1})

{"ErrMsg": "Access denied; Use admin db "," OK ": 0}

Use admin

> Db.runcommand ({fsync:1,lock:1})

{

"Info": "Now locked against writes, use Db.fsyncunlock () to unlock",

"Seealso": "Http://www.mongodb.org/display/DOCS/fsync+Command",

"OK": 1

}

5. View current lock status

Copy Code code as follows:

Db.currentop ()

> Db.currentop ()

{

"InProg": [],

"Fsynclock": 1,

"Info": "Use Db.fsyncunlock () to terminate the Fsync write/snapshot lock"

}

Where Fsynclock 1 represents the MongoDB Fsync process (responsible for synchronizing write changes to disk) does not allow other processes to perform write data operations

6, Unlock

Copy Code code as follows:

Use admin

>db.fsyncunlock ()

{"OK": 1, "info": "Unlock Completed"}

Db. $cmd. Sys.unlock.findOne () Effect equivalent

> Db.currentop ()

{"InProg": []}

Indicates that there are no locks currently available to perform write data operations.

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.