mongodb經常使用操做

1.無認證啓動mongodbmongodb

numactl --interleave=all /usr/local/mongodb/bin/mongod --port %d --master --dbpath %s --logpath %s --pidfilepath %s --logappend  --noauth --oplogSize=240 --fork

2.建立mongodb認證json

host=$MONGODB_HOST:$MONGODB_PORT
mongo $host/admin --eval "db.system.version.remove({});"
mongo $host/admin --eval "db.system.version.insert({'_id':'authSchema','currentVersion':3});"
mongo $host/admin --eval "db.createRole({role:'sysadmin',roles:[],privileges:[{resource:{anyResource:true},actions:['anyAction']}]});"
mongo $host/admin --eval "db.createUser({user:'$MONGODB_USER',pwd:'$MONGODB_PASS',roles:['sysadmin']})"

3.啓動認證mongodbapp

numactl --interleave=all /usr/local/mongodb/bin/mongod --port %d --master --dbpath %s --logpath %s --pidfilepath %s --logappend --auth  --keyFile=mongodb_key --oplogSize=240 --fork

4.作mongodb從庫spa

numactl --interleave=all /usr/local/mongodb/bin/mongod --source 主庫ip:主庫端口 --port %d --slave --dbpath %s --logpath %s --pidfilepath %s --logappend --auth --keyFile=mongodb_key  --nohttpinterface --autoresync  --fork

5.外部執行mongodb語句code

echo 'db.gl.scene.drop();' | /usr/local/mongodb/bin/mongo 127.0.0.1:27317/sid${server_id} -uxxx -pxxxx --authenticationMechanism=MONGODB-CR --authenticationDatabase=admin

6.導出某條件的數據【此處不開啓認證】server

/usr/local/mongodb/bin/mongoexport -h ${source_ip} --port ${source_port} -d sid${server_id} -c gl.player_secretary -q {'pi':${pi}} -o gl.player_secretary_${pi}.json

7.刪除某條件的數據blog

echo 'db.gl.player_secretary.remove({\"pi\":${pi}});' | /usr/local/mongodb/bin/mongo 127.0.0.1:27317/sid${server_id} -uxxx -pxxxx --authenticationMechanism=MONGODB-CR --authenticationDatabase=admin

8.導入json數據ip

/usr/local/mongodb/bin/mongoimport -h 127.0.0.1 --port=27317  -uxxx -pxxxx --authenticationMechanism=MONGODB-CR --authenticationDatabase=admin -d sid${server_id} -c gl.player_secretary --upsert gl.player_secretary_${pi}.json
相關文章
相關標籤/搜索