zoukankan      html  css  js  c++  java
  • Enable Authentication on MongoDB

    1、Connect to the server using the mongo shell

    mongo mongodb://localhost:27017
    

      

    2、Create the user administrator

    Change to the admin database:

    use admin
    

      

    db.createUser(
      {
        user: "Admin",
        pwd: "Admin123",
        roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
      }
    )
    

      

    执行成功显示如下提示:

    Then disconnect from the mongo shell (Ctrl+D)

    3、Enable authentication in mongod configuration file

     编辑mongodb 配置文件:

    sudo vim /etc/mongod.conf
    

      

    在 # security: 节点下输入以下内容:

    security:
      authorization: "enabled"
    

      

    4、save the file and restart mongod :

    sudo service mongod restart
    

      

    5、 Connect and authenticate as the user administrator

    mongo mongodb://localhost:27017
    

     

    use admin
    

      

    db.auth("Admin", "Admin123")
    

      

    6、Finally, create additional users as needed

    use BIMDB
    
    db.createUser(
      {
        user: "myTester",
        pwd: "xyz123",
        roles: [ { role: "readWrite", db: "BIMDB" } ]
      }
    )
    

     

    7、use auth on appsetting.json

    mongodb://myTester:xyz123@10.100.150.99:27017/BIMDB
    

      

  • 相关阅读:
    owlsuddimatchmaker安装
    类集
    jsp基本语法
    心得思路记录下
    nyoj517 最小公倍数
    poj1250 Tanning Salon
    poj1686 Lazy Math Instructor
    poj3250 Bad Hair Day
    poj1047 Round and Round We Go
    poj2359 Questions
  • 原文地址:https://www.cnblogs.com/autohome7390/p/10096713.html
Copyright © 2011-2022 走看看