rs是一個全局的變量,其中那個包含與複制相關的輔助函數,這些函數大多隻是資料庫指令的包裝器,例如
1
<code>>db.adminCommand({“replSetInitiate”:config})</code>
就和
<code>>rs.initiate(config)</code>
指令是等價的,但是明顯後者更容易操作;多了解一下輔助函數還是比較利于操作的。
執行rs.help()可檢視可用的輔助函數,如下:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<code>spock:PRIMARY> rs.help() </code>
<code>rs.status() { replSetGetStatus : 1 } checks repl </code><code>set</code> <code>status </code>
<code>rs.initiate() { replSetInitiate : null } initiates </code><code>set</code> <code>with default settings </code>
<code>rs.initiate(cfg) { replSetInitiate : cfg } initiates </code><code>set</code> <code>with configuration cfg </code>
<code>rs.conf() get the current configuration object from </code><code>local</code><code>.system.replset </code>
<code>rs.reconfig(cfg) updates the configuration of a running replica </code><code>set</code> <code>with cfg (disconnects) </code>
<code>rs.add(hostportstr) add a new member to the </code><code>set</code> <code>with default attributes (disconnects) </code>
<code>rs.add(membercfgobj) add a new member to the </code><code>set</code> <code>with extra attributes (disconnects) </code>
<code>rs.addArb(hostportstr) add a new member </code><code>which</code> <code>is arbiterOnly:</code><code>true</code> <code>(disconnects) </code>
<code>rs.stepDown([secs]) step down as primary (momentarily) (disconnects) </code>
<code>rs.syncFrom(hostportstr) </code><code>make</code> <code>a secondary to </code><code>sync</code> <code>from the given member </code>
<code>rs.freeze(secs) </code><code>make</code> <code>a node ineligible to become primary </code><code>for</code> <code>the </code><code>time</code> <code>specified </code>
<code>rs.remove(hostportstr) remove a host from the replica </code><code>set</code> <code>(disconnects) </code>
<code>rs.slaveOk() shorthand </code><code>for</code> <code>db.getMongo().setSlaveOk()</code>
<code>rs.printReplicationInfo() check oplog size and </code><code>time</code> <code>range </code>
<code>rs.printSlaveReplicationInfo() check replica </code><code>set</code> <code>members and replication lag </code>
<code>db.isMaster() check </code><code>who</code> <code>is primary</code>
<code>reconfiguration helpers disconnect from the database so the shell will display an error, even </code><code>if</code> <code>the </code><code>command</code> <code>succeeds. </code>
<code>see also http:</code><code>//</code><code><mongod_host>:28017</code><code>/_replSet</code> <code>for</code> <code>additional diagnostic info</code>
本文轉自 bannerpei 51CTO部落格,原文連結:http://blog.51cto.com/281816327/1611295,如需轉載請自行聯系原作者