批量建用户脚本

640阅读 0评论2017-05-03 taohorse
分类:NOSQL

var conn = new Mongo('host:port');
db = conn.getDB('admin');
db.auth('root', 'test');
database_names = ["crawl_data","company_data","crawl_merge_linkattr","crawl_merge_webpage","crawl_params","final_data","mfile","schedule_data","task_collect", 'single_src']
for(var i = 0; i < database_names.length; i++){
    var database_name = database_names[i]
    db = conn.getDB(database_name);
    var result = db.getUser('work')
    if (result != null)
    {
        continue
    }
    db.createUser(
        {
            user:"work",
            pwd:"haizhi",
            roles:[
                {role:"readWrite",db:database_name}
            ]
        }
    )
}

/home/work/env/mongodb/bin/mongo Crawler-DataServer1:40042 create_mongodb.js
上一篇:Python中re(正则表达式)模块详解
下一篇:检查数据库脚本