2014-02-22 57 views

回答

0

從MongoDB的3.0開始u必須使用的createUser,不ADDUSER。 語法是:

db.createUser(
    { 
     user: "username", 
     pwd: "12345678", 
     roles: [ 
     { role: "read", db: "reporting" }, 
     { role: "read", db: "products" }, 
     { role: "read", db: "sales" }, 
     { role: "readWrite", db: "accounts" } 
     ] 
    } 
) 

要添加根admin使用以下命令:

db.createUser({ user: "admin", pwd: "adminpwd", roles: [ "root" ]}) 

看看這裏: http://docs.mongodb.org/manual/tutorial/add-user-to-database/

2

它類似的東西:

db.collection.insert({ user: "username", password: 'password', roles: ['role1','role2']) 
相關問題