| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 
 | //查看当前配置,存入config变量中mongos:PRIMARY> config=rs.conf()
 //修改config变量,将第二个成员的优先级设为2
 mongos:PRIMARY> config.members[1].priority = 2
 2
 //配置生效
 mongos:PRIMARY> rs.reconfig(config)
 // 查看状态
 mongos:PRIMARY> rs.status()
 {
 "set" : "mongos",
 "date" : ISODate("2021-05-06T09:20:57.517Z"),
 "myState" : 2,
 "term" : NumberLong(2),
 "syncSourceHost" : "192.168.6.128:27019",
 "syncSourceId" : 2,
 "heartbeatIntervalMillis" : NumberLong(2000),
 "majorityVoteCount" : 2,
 "writeMajorityCount" : 2,
 "votingMembersCount" : 3,
 "writableVotingMembersCount" : 3,
 "optimes" : {
 "lastCommittedOpTime" : {
 "ts" : Timestamp(1620292840, 1),
 "t" : NumberLong(2)
 },
 "lastCommittedWallTime" : ISODate("2021-05-06T09:20:40.488Z"),
 "readConcernMajorityOpTime" : {
 "ts" : Timestamp(1620292840, 1),
 "t" : NumberLong(2)
 },
 "readConcernMajorityWallTime" : ISODate("2021-05-06T09:20:40.488Z"),
 "appliedOpTime" : {
 "ts" : Timestamp(1620292840, 1),
 "t" : NumberLong(2)
 },
 "durableOpTime" : {
 "ts" : Timestamp(1620292840, 1),
 "t" : NumberLong(2)
 },
 "lastAppliedWallTime" : ISODate("2021-05-06T09:20:40.488Z"),
 "lastDurableWallTime" : ISODate("2021-05-06T09:20:40.488Z")
 },
 "lastStableRecoveryTimestamp" : Timestamp(1620292840, 1),
 "electionParticipantMetrics" : {
 "votedForCandidate" : true,
 "electionTerm" : NumberLong(2),
 "lastVoteDate" : ISODate("2021-05-06T09:20:28.156Z"),
 "electionCandidateMemberId" : 1,
 "voteReason" : "",
 "lastAppliedOpTimeAtElection" : {
 "ts" : Timestamp(1620292817, 1),
 "t" : NumberLong(1)
 },
 "maxAppliedOpTimeInSet" : {
 "ts" : Timestamp(1620292817, 1),
 "t" : NumberLong(1)
 },
 "priorityAtElection" : 1,
 "newTermStartDate" : ISODate("2021-05-06T09:20:28.213Z"),
 "newTermAppliedDate" : ISODate("2021-05-06T09:20:29.266Z")
 },
 "members" : [
 {
 "_id" : 0,
 "name" : "192.168.6.128:27017",
 "health" : 1,
 "state" : 2,
 "stateStr" : "SECONDARY",
 "uptime" : 5418,
 "optime" : {
 "ts" : Timestamp(1620292840, 1),
 "t" : NumberLong(2)
 },
 "optimeDate" : ISODate("2021-05-06T09:20:40Z"),
 "syncSourceHost" : "192.168.6.128:27019",
 "syncSourceId" : 2,
 "infoMessage" : "",
 "configVersion" : 3,
 "configTerm" : 2,
 "self" : true,
 "lastHeartbeatMessage" : ""
 },
 {
 "_id" : 1,
 "name" : "192.168.6.128:27018",
 "health" : 1,
 "state" : 1,
 "stateStr" : "PRIMARY", //已被设置为主节点
 "uptime" : 4824,
 "optime" : {
 "ts" : Timestamp(1620292840, 1),
 "t" : NumberLong(2)
 },
 "optimeDurable" : {
 "ts" : Timestamp(1620292840, 1),
 "t" : NumberLong(2)
 },
 "optimeDate" : ISODate("2021-05-06T09:20:40Z"),
 "optimeDurableDate" : ISODate("2021-05-06T09:20:40Z"),
 "lastHeartbeat" : ISODate("2021-05-06T09:20:55.545Z"),
 "lastHeartbeatRecv" : ISODate("2021-05-06T09:20:56.257Z"),
 "pingMs" : NumberLong(0),
 "lastHeartbeatMessage" : "",
 "syncSourceHost" : "",
 "syncSourceId" : -1,
 "infoMessage" : "",
 "electionTime" : Timestamp(1620292828, 1),
 "electionDate" : ISODate("2021-05-06T09:20:28Z"),
 "configVersion" : 3,
 "configTerm" : 2
 },
 {
 "_id" : 2,
 "name" : "192.168.6.128:27019",
 "health" : 1,
 "state" : 2,
 "stateStr" : "SECONDARY",
 "uptime" : 924,
 "optime" : {
 "ts" : Timestamp(1620292840, 1),
 "t" : NumberLong(2)
 },
 "optimeDurable" : {
 "ts" : Timestamp(1620292840, 1),
 "t" : NumberLong(2)
 },
 "optimeDate" : ISODate("2021-05-06T09:20:40Z"),
 "optimeDurableDate" : ISODate("2021-05-06T09:20:40Z"),
 "lastHeartbeat" : ISODate("2021-05-06T09:20:55.543Z"),
 "lastHeartbeatRecv" : ISODate("2021-05-06T09:20:56.547Z"),
 "pingMs" : NumberLong(0),
 "lastHeartbeatMessage" : "",
 "syncSourceHost" : "192.168.6.128:27018",
 "syncSourceId" : 1,
 "infoMessage" : "",
 "configVersion" : 3,
 "configTerm" : 2
 }
 ],
 "ok" : 1,
 "$clusterTime" : {
 "clusterTime" : Timestamp(1620292840, 1),
 "signature" : {
 "hash" : BinData(0,"OizMd+vrzvez8MC+7baAHt0Iy8M="),
 "keyId" : NumberLong("6959084154784841732")
 }
 },
 "operationTime" : Timestamp(1620292840, 1)
 }
 
 |