MongoDB Startup and user name password settings

Source: Internet
Author: User
Tags auth mongodb server

1. Service Start-up
    • After downloading the installation steps, please see the MongoDB installation detailed tutorial
    • Start the serviceNET START MongoDB
    • Close ServiceNET STOP MongoDB
    • Start the client MONGO
      • MongoDB Shell version v3.6.0
      • Connecting to:mongodb://127.0.0.1:27017
      • MongoDB Server version:3.6.0
2. Set password and user rights 2.1 turn on security verification
    • Mode one: At the command line inputmongod --auth --logpath "D:\Program Files\mongodb\data\log\MongoDB.log" --logappend --dbpath "D:\Program Files\mongodb\data\db" --directoryperdb --reinstall
    • Mode two: input at the command linemongod --dbpath "G:\mongoDB\data\db" --logpath "G:\mongoDB\data\log\MongoDB.log" --auth
2.2 Creating a user
    • Navigate to D:\Program Files \mongodb\bin and use Mongo.exe to enter MongoDB's command line management.
    • Type the following command >use admin >db.createUser({user:"yangjing",pwd:"123456",roles:["userAdminAnyDatabase"]})
    • Now we add a user root for the MongoDB Admin database, and the password is ROOT,MONGODB can establish permission authentication for each database, that is, you can specify which database a user can log into. The above code, we added a root user for the admin database, in MongoDB, the admin database is a special database, the user of this database can access all the databases in MongoDB.
      If you want to set up a user for the test database, use the following command
    • >use test>db.createUser({user:"yangjing",pwd:"123456"})
      OK, now that we've set up a global user root for MongoDB, we'll restart MongoDB to make the created user effective.
2.3 User Login
    • The first thing you need to do is jump to the current database mode using the "Use database name, such as: Usage admin", then log in下面1表示登录成功,0表示登录失败。
    • db.auth("yangjing","123456")

MongoDB Startup and user name password settings

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.