mongodb 添加用户报错TypeError:db.addUser is not a function (mongodb3.4.1)
来源:互联网 发布:fastdfs nginx 编辑:程序博客网 时间:2024/05/16 06:26
1:问题如下:
原因是 新版的MongoDB已经不支持addUser方法了。
改成createUser了。
使用方法如下
2:具体解释一下db.createUser()方法的用法
定义:
创建一个数据库新用户用db.createUser()方法,如果用户存在则返回一个用户重复错误。语法:
db.createUser(user, writeConcern)
user这个文档创建关于用户的身份认证和访问信息;
writeConcern这个文档描述保证MongoDB提供写操作的成功报告。
· user文档,定义了用户的以下形式:
{ user: "<name>",
pwd: "<cleartext password>",
customData: { <any information> },
roles: [
{ role: "<role>", db: "<database>" } | "<role>",
...
]
}
user文档字段介绍:
user字段,为新用户的名字;
pwd字段,用户的密码;
cusomData字段,为任意内容,例如可以为用户全名介绍;
roles字段,指定用户的角色,可以用一个空数组给新用户设定空角色;
在roles字段,可以指定内置角色和用户定义的角色。
Built-In Roles(内置角色):
1. 数据库用户角色:read、readWrite;
2. 数据库管理角色:dbAdmin、dbOwner、userAdmin;
3. 集群管理角色:clusterAdmin、clusterManager、clusterMonitor、hostManager;
4. 备份恢复角色:backup、restore;
5. 所有数据库角色:readAnyDatabase、readWriteAnyDatabase、userAdminAnyDatabase、dbAdminAnyDatabase
6. 超级用户角色:root
// 这里还有几个角色间接或直接提供了系统超级用户的访问(dbOwner 、userAdmin、userAdminAnyDatabase)
7. 内部角色:__system
PS:关于每个角色所拥有的操作权限可以点击上面的内置角色链接查看详情。
· writeConcern文档(官方说明)
w选项:允许的值分别是 1、0、大于1的值、"majority"、<tag set>;
j选项:确保mongod实例写数据到磁盘上的journal(日志),这可以确保mongd以外关闭不会丢失数据。设置true启用。
wtimeout:指定一个时间限制,以毫秒为单位。wtimeout只适用于w值大于1。
例如:在products数据库创建用户accountAdmin01,并给该用户admin数据库上clusterAdmin和readAnyDatabase的角色,products数据库上readWrite角色。
use products
db.createUser( { "user" : "accountAdmin01",
"pwd": "cleartext password",
"customData" : { employeeId: 12345 },
"roles" : [ { role: "clusterAdmin", db: "admin" },
{ role: "readAnyDatabase", db: "admin" },
"readWrite"
] },
{ w: "majority" , wtimeout: 5000 } )
验证:
mongo -u accountAdmin01 -p yourpassward --authenticationDatabase products
阅读全文
0 0
- mongodb 添加用户报错TypeError:db.addUser is not a function (mongodb3.4.1)
- mongodb 添加用户报错TypeError:db.addUser is not a function (mongodb3.4.1)
- mongodb 添加用户报错TypeError:db.addUser is not a function (mongodb3.4.1)
- mongodb 添加用户报错TypeError:db.addUser is not a function
- MongoDB(version3.2)创建用户报错addUser is not a function
- MongoDB创建管理员时报错db.addUser is not a function
- js报错:TypeError: document.GetElementById is not a function
- js报错 :TypeError: yanzhengma is not a function
- js报错:TypeError: document.GetElementById is not a function
- jquery.js里面报错Uncaught TypeError: a.indexOf is not a function
- TypeError: a(...).live is not a function(jquery.unobtrusive-ajax.min.js 引入报错)
- JS报错 Uncaught TypeError: undefined is not a function,解决
- jquery提交表单报错 Uncaught TypeError: s[y] is not a function
- js 函数报错“Uncaught: TypeError xxx is not a function”
- jQuery中live()使用报错,TypeError: $(...).live is not a function
- 报错:Uncaught TypeError: $(…).dialog is not a function,处理方法。
- swagger1.2浏览器报错Uncaught TypeError: detectedType.toLowerCase is not a function
- jQuery中live()使用报错,TypeError: $(...).live is not a function(转)
- bzoj1003 [ZJOI2006]物流运输(最短路+dp)
- HDU 5187 zhx's contest (解决LL*LL%mod)(mod为LL型)
- 51Nod 1256:乘法逆元
- get请求数据(图片)
- 快速幂模板
- mongodb 添加用户报错TypeError:db.addUser is not a function (mongodb3.4.1)
- Codevs 1069 && 洛谷 1525 关押罪犯 并查集
- 软件测试之性能测试
- 升级Ubuntu内核
- JS中null和undefined的区别以及使用情况
- (三)爬取百度帖子(完善)
- Java1.7ConcurrentHashMap类源码解析
- 我的第一篇博客
- Manthan, Codefest 17 E. Salazar Slytherin's Locket 数位DP+状态压缩