发布于 2015-09-14 14:58:09 | 238 次阅读 | 评论: 0 | 来源: 网络整理

rs.add(hostspec, arbiterOnly)

Specify one of the following forms:

参数:
  • host (string,document) – Either a string or a document. If a string, specifies a host (and optionally port-number) for a new host member for the replica set; MongoDB will add this host with the default configuration. If a document, specifies any attributes about a member of a replica set.
  • arbiterOnly (boolean) – Optional. If true, this host is an arbiter. If the second argument evaluates to true, as is the case with some documents, then this instance will become an arbiter.

Provides a simple method to add a member to an existing replica set. You can specify new hosts in one of two ways:

  1. as a “hostname” with an optional port number to use the default configuration as in the Add a Member to an Existing Replica Set example.
  2. as a configuration document, as in the Add a Member to an Existing Replica Set (Alternate Procedure) example.

This function will disconnect the shell briefly and forces a reconnection as the replica set renegotiates which node will be primary. As a result, the shell will display an error even if this command succeeds.

rs.add() provides a wrapper around some of the functionality of the “replSetReconfigdatabase command and the corresponding shell helper rs.reconfig(). See the 副本集配置 document for full documentation of all replica set configuration options.

Example

To add a mongod accessible on the default port 27017 running on the host mongodb3.example.net, use the following rs.add() invocation:

rs.add('mongodb3.example.net:27017')

If mongodb3.example.net is an arbiter, use the following form:

rs.add('mongodb3.example.net:27017', true)

To add mongodb3.example.net as a secondary-only member of set, use the following form of rs.add():

rs.add( { "host": "mongodbd3.example.net:27017", "priority": 0 } )

See the 副本集配置 and 副本集的操作和管理 documents for more information.

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务