SHELL腳本執行mongodb 添加用戶權限


fit_mongo.sh和fit_mongo.sh在同一級目錄下:

MongoDB添加用戶:

1、設置權限:mongodb.conf中添加

auth =true

2、啟動mongoDB:

cd mongo/mongodb-linux-x86_64-rhel62-4.2.3/bin/
./mongod -f ../../mongodb.conf

3、執行腳本

fit_mongo.sh

#!/bin/bash
cd mongo/mongodb-linux-x86_64-rhel62-4.2.3/bin/
./mongo --host 127.0.0.1:27017 data ../../../fit_mongo.js >> fit_mongo.log

fit_mongo.js

try{
var database = connect('admin')
database.createUser({user:'root',pwd:'root',roles:['root']});
print('Ready to addRoot');
}catch(err){
print('error message:'+err);
}

 

現在我們為mongodb的admin數據庫添加一個用戶root,密碼也是root,mongodb可以為每個數據庫都建立權限認證,也就是你可以指定某個用戶可以登錄到哪個數據庫。上面的代碼,我們為admin數據庫添加了一個root用戶,在mongodb中admin數據庫是一個特別的數據庫,這個數據庫的用戶,可以訪問mongodb中的所有數據庫。

 

 

 

 

springboot:連接mongo

 

 

mongodb.port=27017
mongodb.host=127.0.0.1
mongodb.dbName=admin
mongodb.userName=root
mongodb.password=123456
org.quartz.jobStore.class=cn.com.rivercloud.report.scheduler.CustomMongoQuartzSchedulerJobStore
org.quartz.jobStore.mongoUri=mongodb://root:123456@127.0.0.1:27017/admin
org.quartz.jobStore.collectionPrefix=quartz
org.quartz.jobStore.isClustered=false
org.quartz.scheduler.skipUpdateCheck=true
org.quartz.scheduler.instanceId=AUTO
org.quartz.scheduler.instanceName=quartzMongoInstance
org.quartz.quartz.jobStore.dbName=data
org.quartz.server.name=quarts-intro
org.quartz.threadPool.threadCount=1

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM