本文共 1074 字,大约阅读时间需要 3 分钟。
在mongodb上添加用户报错,如下:
> db.addUser('user01','123456');2016-07-29T14:50:28.932+0800 E QUERY TypeError: Property 'addUser' of object admin is not a function at (shell):1:4
经查,原因是在mongodb版本3以上已经弃用了adduser,改成createuser了。
[candon@xxx bin]$ ./mongo 127.0.0.1:27017MongoDB shell version: 3.0.6connecting to: 127.0.0.1:27017/test> use adminuse adminswitched to db admin> db.version()3.0.6> db.createUser({user:'user01', pwd:'123456', roles:['userAdminAnyDatabase']})Successfully added user: { "user" : "user01", "roles" : [ "userAdminAnyDatabase" ] }> db.auth("user01","123456")1> show users{ "_id" : "admin.root", "user" : "root", "db" : "admin", "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ]}{ "_id" : "admin.user01", "user" : "user01", "db" : "admin", "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ]}> exitbye
参考文献:
转载地址:http://jygka.baihongyu.com/