blob: eeabba7e10e8726d7a784adbc4988f7c80f0c786 (
plain)
1
2
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
|
// Runner for validateCollections that runs full validation on all collections when loaded into
// the mongo shell.
'use strict';
(function() {
load('jstests/libs/discover_topology.js'); // For Topology and DiscoverTopology.
load('jstests/hooks/validate_collections.js'); // For CollectionValidator.
assert.eq(typeof db, 'object', 'Invalid `db` object, is the shell connected to a mongod?');
const topology = DiscoverTopology.findConnectedNodes(db.getMongo());
const hostList = [];
let setFCVHost;
if (topology.type === Topology.kStandalone) {
hostList.push(topology.mongod);
setFCVHost = topology.mongod;
} else if (topology.type === Topology.kReplicaSet) {
hostList.push(...topology.nodes);
setFCVHost = topology.primary;
} else if (topology.type === Topology.kShardedCluster) {
hostList.push(...topology.configsvr.nodes);
for (let shardName of Object.keys(topology.shards)) {
const shard = topology.shards[shardName];
if (shard.type === Topology.kStandalone) {
hostList.push(shard.mongod);
} else if (shard.type === Topology.kReplicaSet) {
hostList.push(...shard.nodes);
} else {
throw new Error('Unrecognized topology format: ' + tojson(topology));
}
}
// Any of the mongos instances can be used for setting FCV.
setFCVHost = topology.mongos.nodes[0];
} else {
throw new Error('Unrecognized topology format: ' + tojson(topology));
}
new CollectionValidator().validateNodes(hostList, setFCVHost);
})();
|