温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

【MongoDB学习笔记33】MongoDB副本集rs辅助函数

发布时间:2020-06-18 16:10:13 来源:网络 阅读:1350 作者:StanlyCheng 栏目:MongoDB数据库

rs是一个全局的变量,其中那个包含与复制相关的辅助函数,这些函数大多只是数据库命令的包装器,例如

>db.adminCommand({“replSetInitiate”:config})

就和

>rs.initiate(config)

命令是等价的,但是明显后者更容易操作;多了解一下辅助函数还是比较利于操作的。

执行rs.help()可查看可用的辅助函数,如下:

spock:PRIMARY> rs.help()           
rs.status()    { replSetGetStatus : 1 } checks repl set status            
rs.initiate()    { replSetInitiate : null } initiates set with default settings     
rs.initiate(cfg)  { replSetInitiate : cfg } initiates set with configuration cfg   
rs.conf()      get the current configuration object from local.system.replset 
rs.reconfig(cfg)  updates the configuration of a running replica set with cfg (disconnects)            
rs.add(hostportstr) add a new member to the set with default attributes (disconnects) 
rs.add(membercfgobj) add a new member to the set with extra attributes (disconnects)   
rs.addArb(hostportstr)   add a new member which is arbiterOnly:true (disconnects)   
rs.stepDown([secs])   step down as primary (momentarily) (disconnects)         
rs.syncFrom(hostportstr)        make a secondary to sync from the given member  
rs.freeze(secs)    make a node ineligible to become primary for the time specified 
rs.remove(hostportstr) remove a host from the replica set (disconnects)      
rs.slaveOk()      shorthand for db.getMongo().setSlaveOk()
rs.printReplicationInfo()  check oplog size and time range           
rs.printSlaveReplicationInfo()  check replica set members and replication lag     
db.isMaster()                   check who is primary
reconfiguration helpers disconnect from the database so the shell will display an error, even if the command succeeds.            
see also http://<mongod_host>:28017/_replSet for additional diagnostic info



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI