How to create a user in MongoDB v3.0.5

后端 未结 1 2096
失恋的感觉
失恋的感觉 2021-02-10 03:20

I need to create a user for my database in mongodb, but it seems that I can\'t get it to work.

I have installed mongoDb v3.0.5 on my windows 7 machine. according to this

相关标签:
1条回答
  • 2021-02-10 03:59

    When you "use admin", your new user is created in database "admin".

    use admin
    db.createUser(
      {
        user: "myUser",
        pwd: "123456",
        roles: [ { role: "readWrite", db: "exampleDb" } ]
      }
    )
    

    So your connection string must be as:

    var connString = "mongodb://myUser:123456@127.0.0.1:27017/admin";
    
    0 讨论(0)
提交回复
热议问题