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
相关文章
相关标签/搜索