大佬教程收集整理的这篇文章主要介绍了node.js – 使用Mongoose进行Mongodb安全服务器设置,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
>如何使用mongoose创建用户,以便只有该用户才能访问数据库?
>在/etc/mongodb.conf上我应该只添加bind_ip = 0.0.0.0,那就是全部?
PS:我正在使用Ubuntu 16:04和最新的Mongodb.
编辑:17/08/17
我到目前为止取得的成功是addUser = db.createUser({user:“admin”,pwd:“admin”,roles:[{role:“userAdminAnyDatabase”,db:“admin”}]});对于管理数据库,当数据库在–auth下并且尝试通过该连接创建其他数据库时连接它,如下所示.
var adminConnection = mongoose.createConnection('mongodb://admin:admin@localhost:27017/admin',{ useMongoClient: true }); console.log(typeof adminConnection.db.executeDbAdminCommand);//function
Your /etc/mongod.conf YAML file will be look like this storage: dbPath: /var/lib/mongodb journal: enabled: true # where to write logging data. systemLog: desTination: file logAppend: true path: /var/log/mongodb/mongod.log # network interfaces put your ip in bindIp in form of Array like below net: port: 27017 bindIp: [127.0.0.1,84.20.57.18] #before enabling security authorization you must add mongodb database user security: authorization: "enabled" #Replication oplogsize mb set based on Main Memory of your Ubuntu Server (It will be good to set 1024 for speed of database Operation). In replSetName give your Replica set name or your Project Name Ex: smartcity Replication: oplogSizeMB: 1024 replSetName: "smartcity"
在节点js中如何使用mongoose并连接到您的mongodb数据库,如下所示
var mongoose = require('mongoose'); var options = { useMongoClient:true }; var dbUrl = 'mongodb://<dbusername>:<dbpassword>@<db-ipaddress>:27017/<dbname>?replicaset=<replicasetname>';//Ex:"mongodb://smartcityUser:smartcity1234@84.20.57.18:27017/smartcity?replicaset=smartcity" mongoose.connect(dbUrl,options); mongoose.Promise = global.Promise;
愿我的工作能够最好地解决您的问题
以上是大佬教程为你收集整理的node.js – 使用Mongoose进行Mongodb安全服务器设置全部内容,希望文章能够帮你解决node.js – 使用Mongoose进行Mongodb安全服务器设置所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。