一、数据库相关命令:
1、显示当前数据库版本号:
rs1:SECONDARY> db.version() 3.6.3
2、查询当前所连接的 MongoDB 实例:
rs1:SECONDARY> db.getMongo() connection to 127.0.0.1:27018
3、查询当前所使用数据库的名称:
rs1:SECONDARY> db.getName() test
4、显示当前数据库相关信息:
rs2:SECONDARY> db.stats()
5、赋予复制集群中的次要节点,具有执行查询命令的权限:
rs1:SECONDARY> db.getMongo().setSlaveOk()
二、复制集(Replica Set)相关命令:
1、显示当前复制集的状态信息:
rs2:SECONDARY> rs.status()
2、显示当前复制集的配置信息:
rs2:SECONDARY> rs.conf()
3、将当前主要节点降级为次要节点
rs1:PRIMARY> rs.stepDown([stepdownSecs, catchUpSecs]) rs1:PRIMARY> rs.stepDown()
4、显示 oplog 复制数据信息:
rs1:SECONDARY> rs.printReplicationInfo() configured oplog size: 1129.7734375MB log length start to end: 11010secs (3.06hrs) oplog first event time: Fri Feb 19 2021 08:06:02 GMT+0800 (CST) oplog last event time: Fri Feb 19 2021 11:09:32 GMT+0800 (CST) now: Fri Feb 19 2021 11:09:32 GMT+0800 (CST)
5、显示复制集中次要节点与主节点之间的连接信息:
rs1:PRIMARY> rs.printSlaveReplicationInfo() source: 172.16.2.154:27018 syncedTo: Fri Feb 19 2021 11:06:11 GMT+0800 (CST) 0 secs (0 hrs) behind the primary source: 172.16.1.154:27018 syncedTo: Fri Feb 19 2021 11:06:13 GMT+0800 (CST) -2 secs (0 hrs) behind the primary
6、指定当前节点的上级数据同步节点(次要节点):
rs1:SECONDARY> rs.syncFrom(hostportstr) rs1:SECONDARY> rs.syncFrom("172.16.2.155:27018")
7、显示当前节点的上级数据同步节点(次要节点):
rs1:SECONDARY> rs.status().syncingTo 172.16.1.155:27018
8、向复制集中添加一个节点:
rs1:PRIMARY> rs.add(hostportstr) rs1:PRIMARY> rs.add({"172.16.1.155:27018") rs1:PRIMARY> rs.add({host:'172.16.1.155:27018',priority:1,votes:1})
9、从复制集中删除一个节点:
rs1:PRIMARY> rs.remove(hostportstr) rs1:PRIMARY> rs.remove({"172.16.1.155:27018")
[THE END]