forked from mongodb/mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunique_index_empty_collmod.js
43 lines (38 loc) · 1.81 KB
/
unique_index_empty_collmod.js
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
43
/**
* Ensure that unique indexes are not updated on running an empty collMod command with FCV=4.0.
* Creates a unique index, downgrades the FCV, and runs collMod on the collection.
* @tags: [requires_replication, requires_wiredtiger]
*/
(function() {
'use strict';
const newIndexFormatVersion = 12;
const rst = new ReplSetTest({nodes: [{}, {rsConfig: {priority: 0, votes: 0}}]});
const nodes = rst.startSet();
rst.initiate();
let dbName = 'test';
let collName = 't';
const primary = rst.getPrimary();
const primaryDb = primary.getDB(dbName);
const secondary = rst.getSecondary();
const coll = primaryDb.getCollection(collName);
assert.commandWorked(coll.createIndex({a: 1}, {unique: true}));
assert.writeOK(coll.insert({_id: 0, a: 1}));
assert.commandWorked(primaryDb.adminCommand({setFeatureCompatibilityVersion: '4.0'}));
assert.commandWorked(primaryDb.runCommand({collMod: coll.getName()}));
// Wait for replication of the index creation.
rst.awaitReplication();
const secondaryDb = secondary.getDB(dbName);
const coll_secondary = secondaryDb.getCollection(collName);
const index = coll_secondary.getIndexes();
assert.eq(index[1].unique, true, "Expected a unique index: " + tojson(index[1]));
// Validate that the unique index is not updated on the secondary after an empty collMod
// command.
const indexFormatVersion = coll_secondary.aggregate({$collStats: {storageStats: {}}})
.next()
.storageStats.indexDetails[index[1].name]
.metadata.formatVersion;
assert.eq(indexFormatVersion,
newIndexFormatVersion,
"Expected index format version 12 for the unique index: " + tojson(index[1]));
rst.stopSet();
})();