发布时间:2019-07-11 09:55:55编辑:auto阅读(1441)
在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:27017 MongoDB shell version: 3.0.6 connecting to: 127.0.0.1:27017/test > use adminuse admin switched 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" } ] } > exit bye
参考文献:MongoDB常用操作命令大全
上一篇: [Unity3d]unity与html通
下一篇: GNS3-ENSP对接实验
47479
45781
36780
34302
28950
25586
24431
19602
19089
17623
5454°
6037°
5553°
5628°
6554°
5365°
5366°
5872°
5845°
7159°