Access Control for MongoDB learning and sorting

Source: Internet
Author: User

1. Restrict access from specific IP addresses. You only need to add the -- bind_ip parameter at startup, and add the -- Host parameter at client connection.
/APP/Mongo/MongoDB/bin/mongod -- dbpath =/APP/Mongo/MongoDB/data/test -- logpath =/APP/Mongo/MongoDB/data/test/server. log -- fork -- bind_ip 132.42.33.190
/APP/Mongo/MongoDB/bin/Mongo -- Host 132.42.33.190

2. Set the port. You only need to add the -- port parameter at startup and add the -- port parameter at client connection.
/APP/Mongo/MongoDB/bin/mongod -- dbpath =/APP/Mongo/MongoDB/data/test -- logpath =/APP/Mongo/MongoDB/data/test/server. log -- fork -- Port 28018
/APP/Mongo/MongoDB/bin/Mongo -- Port 28012

3. user verification management
By default, MongoDB has an admin database. users in the admin database have higher permissions than those in other databases, that is, users in the admin database can perform any operation on other databases.

Enable: login verification
/APP/Mongo/MongoDB/bin/mongod -- dbpath =/APP/Mongo/MongoDB/data/test -- logpath =/APP/Mongo/MongoDB/data/test/server. log -- fork -- auth

Note: MongoDB has an admin database by default. If there is no data in Admin. system. Users, login verification will not take effect.

1) create a user
> DB. adduser ("root", "111111") -- create a user
> DB. Auth ("root", "111111") -- set the user to have database connection Verification

2) create a user with the specified permission,
Command Format: DB. adduser (username, password [, readonly = false])

For example, add a read-only user user_reader to the test database. The Code is as follows:
> DB. adduser ("user_reader", "passw0rd", true) -- creates a read-only user.
> Show collections -- View
System. Indexes
System. Users
> DB. t1.insert ({name: "liangzhangping", age: 29}) -- but cannot be added, deleted, or updated.
Unauthorized

3) delete a specified user. Call the DB. removeuser (username) command to delete the user. You can call dB. system. Users. Find () to check whether the user is deleted.
> DB. removeuser ("user_reader ")
> DB. system. Users. Find ()
{"_ Id": objectid ("4fd9c4bc869208ca70bcf180"), "user": "test", "readonly": false, "PWD": "success "}

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.