mongo常用
查看从同步
db.printSlaveReplicationInfo()
db.printReplicationInfo()
查看collection大小
db.wallet.dataSize()
改主从
cfg.members[5].priority= 1
rs.reconfig(cfg)
rs.syncFrom("10.90.70.170:27017")
加索引
db.video.dataSize()
use fhh
db.wemedia_account.ensureIndex({"categoryId":1,"online":1})
db.wemedia_account.getIndexes()
mongo -u"fhh_super_p" -p"fhh_super_p" --authenticationDatabase=admin --host 127.0.0.1:37017
rs.slaveOk()
db.article.getIndexes()
db.video.totalIndexSize()
用户
修改
db.updateUser(
"user3",
{
customDate:{"any information"},
roles: [
{ role: "dbOwner", db: "db1" },
{ role: "clusterManager", db: "admin" }
],
pwd:"password"
},
writeconcem:{<write concem>}
)
创建用户
use admin
db.createUser({user:"root",pwd:"rootpwd",roles:[{role:"root",db:"admin"}]})
查看状态
db.serverStatus() #可查看当前数据库服务器参数连接数等参数
db.stats()
db.system.profile.find()
副本操作
rs.add({_id: 3, host: "127.0.0.1:27017", priority: 0, hidden: true})
rs.remove("127.0.0.1:27017")
cfg.members[1].slaveDelay = 3600
分片自动平衡
use config
sh.getBalancerState()