MongoDB 复制命令
MongoDB isMaster 命令
通过 isMaster 命令返回的文档描述了 mongod 实例的角色。为了创建特定用户的凭据,使用了一个 SASL 机制的数组。当指定 saslSupportMechs 作为可选字段时返回。如果实例是副本集的成员,则 isMaster 命令返回副本集的子集。
当发送给不是副本集成员的 mongod 实例时,isMaster 命令返回相关的信息。
语法:
db.runCommand( { isMaster: 1 } )
MongoDB replySetAbortPrimaryCatchUp命令
该命令强制指定的副本集主节点结束同步,然后完成转换为主节点的过程。
语法:
{ replSetAbortPrimaryCatchUp: 1 }
MongoDB replSetGetConfig 命令
该命令返回一个文档,指定了副本集的当前配置。为了直接获取该命令,我们必须使用以下操作:
语法:
db.runCommand( { replSetGetConfig: 1 } );
例如: - 我们有一个表示副本集配置的文档。它可能只包含以下设置的子集:
{
_id: <string>,
version: <int>,
protocolVersion: <number>,
writeConcernMajorityJournalDefault: <boolean>,
configsvr: <boolean>,
members: [
{
_id: <int>,
host: <string>,
arbiterOnly: <boolean>,
buildIndexes: <boolean>,
hidden: <boolean>,
priority: <number>,
tags: <document>,
slaveDelay: <int>,
votes: <number>
},
...
],
settings: {
chainingAllowed : <boolean>,
heartbeatIntervalMillis : <int>,
heartbeatTimeoutSecs: <int>,
electionTimeoutMillis : <int>,
catchUpTimeoutMillis : <int>,
getLastErrorModes : <document>,
getLastErrorDefaults : <document>,
replicaSetId: <ObjectId>
}
}
MongoDB replSetInitiate 命令
replSetInitiate 命令用于初始化新的副本集。
语法:
{ replSetInitiate : <config_document> }
将文档传递给 rs.initiate() 辅助程序的示例:
MongoDB replSetGetStatus 命令
该命令向副本集返回状态。它从用于处理文档的服务器返回。此命令返回的数据派生自其他集合成员发送给服务器的信号中包含的数据。
语法:
db.adminCommand( { replSetGetStatus: 1 } )
示例:
db.adminCommand( { replSetGetStatus : 1 } )
{
"set" : "replset",
"date" : ISODate("2019-12-04T04:49:18.693Z"),
"myState" : 1,
"term" : NumberLong(3),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"majorityVoteCount" : 2,
"writeMajorityCount" : 2,
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"lastCommittedWallTime" : ISODate("2019-12-04T04:49:14.378Z"),
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"readConcernMajorityWallTime" : ISODate("2019-12-04T04:49:14.378Z"),
"appliedOpTime" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"durableOpTime" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"lastAppliedWallTime" : ISODate("2019-12-04T04:49:14.378Z"),
"lastDurableWallTime" : ISODate("2019-12-04T04:49:14.378Z")
},
"lastStableRecoveryTimestamp" : Timestamp(1575434935, 1),
"lastStableCheckpointTimestamp" : Timestamp(1575434935, 1),
"electionCandidateMetrics" : {
"lastElectionReason" : "stepUpRequestSkipDryRun",
"lastElectionDate" : ISODate("2019-12-04T04:49:04.085Z"),
"electionTerm" : NumberLong(3),
"lastCommittedOpTimeAtElection" : {
"ts" : Timestamp(1575434935, 1),
"t" : NumberLong(2)
},
"lastSeenOpTimeAtElection" : {
"ts" : Timestamp(1575434935, 1),
"t" : NumberLong(2)
},
"numVotesNeeded" : 2,
"priorityAtElection" : 1,
"electionTimeoutMillis" : NumberLong(10000),
"priorPrimaryMemberId" : 1,
"numCatchUpOps" : NumberLong(0),
"newTermStartDate" : ISODate("2019-12-04T04:49:04.366Z"),
"wMajorityWriteAvailabilityDate" : ISODate("2019-12-04T04:49:04.382Z")
},
"electionParticipantMetrics" : {
"votedForCandidate" : true,
"electionTerm" : NumberLong(2),
"lastVoteDate" : ISODate("2019-12-04T04:16:54.398Z"),
"electionCandidateMemberId" : 1,
"voteReason" : "",
"lastAppliedOpTimeAtElection" : {
"ts" : Timestamp(1575433013, 1),
"t" : NumberLong(1)
},
"maxAppliedOpTimeInSet" : {
"ts" : Timestamp(1575433013, 1),
"t" : NumberLong(1)
},
"priorityAtElection" : 1
},
"members" : [
{
"_id" : 0,
"name" : "m1.example.net:27017",
"ip" : "198.51.100.1",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 2019,
"optime" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"optimeDate" : ISODate("2019-12-04T04:49:14Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1575434944, 1),
"electionDate" : ISODate("2019-12-04T04:49:04Z"),
"configVersion" : 1,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "m2.example.net:27017",
"ip" : "198.51.100.2",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 2016,
"optime" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"optimeDurable" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"optimeDate" : ISODate("2019-12-04T04:49:14Z"),
"optimeDurableDate" : ISODate("2019-12-04T04:49:14Z"),
"lastHeartbeat" : ISODate("2019-12-04T04:49:18.138Z"),
"lastHeartbeatRecv" : ISODate("2019-12-04T04:49:18.460Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "m1.example.net:27017",
"syncSourceHost" : "m1.example.net:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 1
},
{
"_id" : 2,
"name" : "m3.example.net:27017",
"ip" : "198.51.100.3",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 2016,
"optime" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"optimeDurable" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"optimeDate" : ISODate("2019-12-04T04:49:14Z"),
"optimeDurableDate" : ISODate("2019-12-04T04:49:14Z"),
"lastHeartbeat" : ISODate("2019-12-04T04:49:18.138Z"),
"lastHeartbeatRecv" : ISODate("2019-12-04T04:49:17.739Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "m1.example.net:27017",
"syncSourceHost" : "m1.example.net:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 1
}
],
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1575434954, 1),
"signature" : {
"hash" : BinData(0,"Dz4WAzT3KpB5XHXwy3MgcjL3M8Q="),
"keyId" : NumberLong("6766433010175705091")
}
},
"operationTime" : Timestamp(1575434954, 1)
}
输出