mongoDB add user in v3.0 问题的解决(Property 'addUser' of object admin is not a func)

mongoDB add user in v3.0 问题的解决(Property 'addUser' of object admin is not a func)
#
问题:创建mongodb帐户时,出错
> db.addUser('jyu', 'aerohive') 
2015-08-05T20:03:02.767+0800 E QUERY    TypeError: Property 'addUser' of object admin is not a function

#步骤1:
刚开始以为是权限问题, 以非auth方式重启mongodb
mongod --dbpath=/opt/mongodb/data --logpath=/opt/mongodb/logs/MongoDB.log -port=27017 --fork
(注: 需要auth的,启动命令为:
mongod --dbpath=/opt/mongodb/data --logpath=/opt/mongodb/logs/MongoDB.log --auth --port=27017 --fork )
#步骤2:
仍然提示出错,然后查找到原因,原来是V3版本mongoDB已经不再使用addUser,而是采用了db.createUser

#最终解决方案:
采用以下这种方式增加用户
参考: http://docs.mongodb.org/manual/reference/method/db.createUser/#create-administrative-user-with-roles
db.createUser(
   {
     user: "accountUser",
     pwd: "password",
     roles: [ "readWrite", "dbAdmin" ]
   }
)
#

你可能感兴趣的:(mongoDB add user in v3.0 问题的解决(Property 'addUser' of object admin is not a func))