mongodb 添加用户报错TypeError:db.addUser is not a function (mongodb3.4.1)
来源:互联网 发布:数位板绘画软件 编辑:程序博客网 时间:2024/04/30 16:02
原因是 新版的MongoDB已经不支持addUser方法了,改成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、dbAdminAnyDatabase6. 超级用户角色:root // 这里还有几个角色间接或直接提供了系统超级用户的访问(dbOwner 、userAdmin、userAdminAnyDatabase)7. 内部角色:__systemPS:关于每个角色所拥有的操作权限可以点击上面的内置角色链接查看详情。
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 productsdb.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(转)
- Python中读取txt文本出现“ 'gbk' codec can't decode byte 0xbf in position 2: illegal multibyte sequence”的解决办法
- [置顶]树莓派B+使用心得
- hdu 4578 Transformation(线段树+多种操作)
- [置顶]SFTP服务的使用!!
- [置顶]eNSP仿真学习,网络入门!
- mongodb 添加用户报错TypeError:db.addUser is not a function (mongodb3.4.1)
- common-pool2连接池详解与使用
- 喷水装置(二)
- mysql的alter用法
- 创建节点的三种方法
- jsp九大内置对象和四个作用域
- Spark MLlib StreamingKmeans 实时KMeans聚类算法源代码解读
- Qt对话框中英文转换
- AsyncTask 第一篇使用篇