Microsoft Windows [Version 10.0.22631.
3447]
(c) Microsoft Corporation. All rights reserved.
C:\Users\imquo>mongosh --port 30002
Current Mongosh Log ID: 661e29923a2e048d3148ec64
Connecting to: mongodb://127.0.0.1:30002/?
directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.1.5
Using MongoDB: 7.0.6
Using Mongosh: 2.1.5
mongosh 2.2.4 is available for download: https://www.mongodb.com/try/download/shell
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
test> rs.initiate()
info2: 'no configuration specified. Using a default configuration for the set',
me: 'localhost:30002',
ok: 1
heThongLuuTru [direct: other] test> use admin
switched to db admin
heThongLuuTru [direct: primary] admin> db.createUser({user: 'admin', pwd: 'admin', roles:['root']})
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1713253012, i: 4 }),
signature: {
hash: Binary.createFromBase64('etkDdhgwF/WobDa5ClnBZaZd6uk=', 0),
keyId: Long('7358365050723106822')
}
},
operationTime: Timestamp({ t: 1713253012, i: 4 })
heThongLuuTru [direct: primary] admin>
(To exit, press Ctrl+C again or Ctrl+D or type .exit)
heThongLuuTru [direct: primary] admin>
C:\Users\imquo>mongosh --host heThongLuuTru/localhost:30002 -u admin admin
Enter password: *****
Current Mongosh Log ID: 661e2b78995b39b6e858e62b
Connecting to: mongodb://<credentials>@localhost:30002/admin?
replicaSet=heThongLuuTru&serverSelectionTimeoutMS=2000&appName=mongosh+2.1.5
Using MongoDB: 7.0.6
Using Mongosh: 2.1.5
mongosh 2.2.4 is available for download: https://www.mongodb.com/try/download/shell
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
heThongLuuTru [primary] admin> rs.add('localhost:30001')
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1713253286, i: 1 }),
signature: {
hash: Binary.createFromBase64('FO+oLFMcoDjBGLKZo6RGz/a31cc=', 0),
keyId: Long('7358365050723106822')
},
operationTime: Timestamp({ t: 1713253286, i: 1 })
heThongLuuTru [primary] admin> rs.add('localhost:30003')
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1713253297, i: 1 }),
signature: {
hash: Binary.createFromBase64('5sm8+5SQqhqRV40fP/ONW/+Nj98=', 0),
keyId: Long('7358365050723106822')
},
operationTime: Timestamp({ t: 1713253297, i: 1 })
heThongLuuTru [primary] admin> rs.isMaster()
topologyVersion: {
processId: ObjectId('661e29783ef40a799067f14e'),
counter: Long('7')
},
hosts: [ 'localhost:30002', 'localhost:30001', 'localhost:30003' ],
setName: 'heThongLuuTru',
setVersion: 5,
ismaster: true,
secondary: false,
primary: 'localhost:30003',
me: 'localhost:30003',
electionId: ObjectId('7fffffff0000000000000002'),
lastWrite: {
opTime: { ts: Timestamp({ t: 1713254635, i: 1 }), t: Long('2') },
lastWriteDate: ISODate('2024-04-16T08:03:55.000Z'),
majorityOpTime: { ts: Timestamp({ t: 1713254635, i: 1 }), t: Long('2') },
majorityWriteDate: ISODate('2024-04-16T08:03:55.000Z')
},
maxBsonObjectSize: 16777216,
maxMessageSizeBytes: 48000000,
maxWriteBatchSize: 100000,
localTime: ISODate('2024-04-16T08:04:05.665Z'),
logicalSessionTimeoutMinutes: 30,
connectionId: 59,
minWireVersion: 0,
maxWireVersion: 21,
readOnly: false,
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1713254635, i: 1 }),
signature: {
hash: Binary.createFromBase64('MFMo0N18sl5FRbX2YRelElBVceQ=', 0),
keyId: Long('7358365050723106822')
},
operationTime: Timestamp({ t: 1713254635, i: 1 }),
isWritablePrimary: true
heThongLuuTru [primary] admin> rs.isMaster()
topologyVersion: {
processId: ObjectId('661e29783ef40a799067f14e'),
counter: Long('7')
},
hosts: [ 'localhost:30002', 'localhost:30001', 'localhost:30003' ],
setName: 'heThongLuuTru',
setVersion: 5,
ismaster: true,
secondary: false,
primary: 'localhost:30003',
me: 'localhost:30003',
electionId: ObjectId('7fffffff0000000000000002'),
lastWrite: {
opTime: { ts: Timestamp({ t: 1713255106, i: 1 }), t: Long('2') },
lastWriteDate: ISODate('2024-04-16T08:11:46.000Z'),
majorityOpTime: { ts: Timestamp({ t: 1713255106, i: 1 }), t: Long('2') },
majorityWriteDate: ISODate('2024-04-16T08:11:46.000Z')
},
maxBsonObjectSize: 16777216,
maxMessageSizeBytes: 48000000,
maxWriteBatchSize: 100000,
localTime: ISODate('2024-04-16T08:11:48.385Z'),
logicalSessionTimeoutMinutes: 30,
connectionId: 59,
minWireVersion: 0,
maxWireVersion: 21,
readOnly: false,
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1713255106, i: 1 }),
signature: {
hash: Binary.createFromBase64('pQQZ24U/yaSUVV/0zwte2fT4Jug=', 0),
keyId: Long('7358365050723106822')
},
operationTime: Timestamp({ t: 1713255106, i: 1 }),
isWritablePrimary: true
heThongLuuTru [primary] admin> rs.add('localhost:30004')
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1713276612, i: 1 }),
signature: {
hash: Binary.createFromBase64('kjf7oIXVVIB94UXj7E1MMmkEUTU=', 0),
keyId: Long('7358365050723106822')
},
operationTime: Timestamp({ t: 1713276612, i: 1 })
heThongLuuTru [primary] admin> rs.addArb('localhost:30005')
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1713276868, i: 1 }),
signature: {
hash: Binary.createFromBase64('Tj8bPPCUuUQ/CMUZVW0evxveM+Q=', 0),
keyId: Long('7358365050723106822')
},
operationTime: Timestamp({ t: 1713276868, i: 1 })
heThongLuuTru [primary] admin> rs.remove("localhost:30004")
MongoServerError[NewReplicaSetConfigurationIncompatible]: Reconfig attempted to install a config
that would change the implicit default write concern. Use the setDefaultRWConcern command to set a
cluster-wide write concern and try the reconfig again.
heThongLuuTru [primary] admin> rs.remove('localhost:30004')
MongoServerError[NewReplicaSetConfigurationIncompatible]: Reconfig attempted to install a config
that would change the implicit default write concern. Use the setDefaultRWConcern command to set a
cluster-wide write concern and try the reconfig again.
heThongLuuTru [primary] admin> rs.conf()
_id: 'heThongLuuTru',
version: 8,
term: 7,
members: [
_id: 0,
host: 'localhost:30002',
arbiterOnly: false,
buildIndexes: true,
hidden: false,
priority: 1,
tags: {},
secondaryDelaySecs: Long('0'),
votes: 1
},
_id: 1,
host: 'localhost:30001',
arbiterOnly: false,
buildIndexes: true,
hidden: false,
priority: 1,
tags: {},
secondaryDelaySecs: Long('0'),
votes: 1
},
_id: 2,
host: 'localhost:30003',
arbiterOnly: false,
buildIndexes: true,
hidden: false,
priority: 1,
tags: {},
secondaryDelaySecs: Long('0'),
votes: 1
},
_id: 3,
host: 'localhost:30004',
arbiterOnly: false,
buildIndexes: true,
hidden: false,
priority: 1,
tags: {},
secondaryDelaySecs: Long('0'),
votes: 1
},
_id: 4,
host: 'localhost:30005',
arbiterOnly: true,
buildIndexes: true,
hidden: false,
priority: 0,
tags: {},
secondaryDelaySecs: Long('0'),
votes: 1
],
protocolVersion: Long('1'),
writeConcernMajorityJournalDefault: true,
settings: {
chainingAllowed: true,
heartbeatIntervalMillis: 2000,
heartbeatTimeoutSecs: 10,
electionTimeoutMillis: 10000,
catchUpTimeoutMillis: -1,
catchUpTakeoverDelayMillis: 30000,
getLastErrorModes: {},
getLastErrorDefaults: { w: 1, wtimeout: 0 },
replicaSetId: ObjectId('661e2a0725f12e8bd65bf506')
heThongLuuTru [primary] admin> rs.setDefaultRWConcern({ w: "majority", wtimeout: 5000 })
TypeError: rs.setDefaultRWConcern is not a function
heThongLuuTru [primary] admin> rs.reconfig({
... _id: "heThongLuuTru",
... members: [
... { _id: 0, host: "localhost:30002" },
... { _id: 1, host: "localhost:30001" },
... { _id: 2, host: "localhost:30003" }
... // Bỏ node localhost:30004 ra khỏi danh sách members
... ]
... })
MongoServerError[NewReplicaSetConfigurationIncompatible]: Non force replica set reconfig can only
add or remove at most 1 voting member.
heThongLuuTru [primary] admin> rs.reconfig({
... _id: "heThongLuuTru",
... members: [
... { _id: 0, host: "localhost:30002" },
... { _id: 1, host: "localhost:30001" },
... { _id: 2, host: "localhost:30003" }]})
MongoServerError[NewReplicaSetConfigurationIncompatible]: Non force replica set reconfig can only
add or remove at most 1 voting member.
heThongLuuTru [primary] admin> rs.isMaster()
topologyVersion: {
processId: ObjectId('661e294c2526acba86775746'),
counter: Long('23')
},
hosts: [
'localhost:30002',
'localhost:30001',
'localhost:30003',
'localhost:30004'
],
arbiters: [ 'localhost:30005' ],
setName: 'heThongLuuTru',
setVersion: 8,
ismaster: true,
secondary: false,
primary: 'localhost:30001',
me: 'localhost:30001',
electionId: ObjectId('7fffffff0000000000000007'),
lastWrite: {
opTime: { ts: Timestamp({ t: 1713277491, i: 1 }), t: Long('7') },
lastWriteDate: ISODate('2024-04-16T14:24:51.000Z'),
majorityOpTime: { ts: Timestamp({ t: 1713277491, i: 1 }), t: Long('7') },
majorityWriteDate: ISODate('2024-04-16T14:24:51.000Z')
},
maxBsonObjectSize: 16777216,
maxMessageSizeBytes: 48000000,
maxWriteBatchSize: 100000,
localTime: ISODate('2024-04-16T14:25:00.431Z'),
logicalSessionTimeoutMinutes: 30,
connectionId: 120,
minWireVersion: 0,
maxWireVersion: 21,
readOnly: false,
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1713277491, i: 1 }),
signature: {
hash: Binary.createFromBase64('tRma6UYDVYRsJn0fR4FPkclfoLk=', 0),
keyId: Long('7358365050723106822')
},
operationTime: Timestamp({ t: 1713277491, i: 1 }),
isWritablePrimary: true
heThongLuuTru [primary] admin>