-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
Copy pathcreate_v1_index.js
38 lines (36 loc) · 1.34 KB
/
create_v1_index.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
/**
* This file defines command overrides to create v:1 indexes by default.
*/
import {OverrideHelpers} from "jstests/libs/override_methods/override_helpers.js";
function runCommandOverride(conn, dbName, cmdName, cmdObj, clientFunction, makeFuncArgs) {
if (cmdName == "createIndexes") {
cmdObj["indexes"].forEach(index => {
// Ignore empty specs
if (Object.keys(index).length == 0) {
return;
}
// Avoid conflicts with the default _id index
if (Object.keys(index["key"]).length == 1 && index["key"]["_id"] == 1) {
return;
}
// v:1 does not support wildcards
for (let key in index["key"]) {
if (key.includes("$**")) {
return;
}
}
// v:1 does not support collation
if ("collation" in index) {
return;
}
// If v is not specified, default to v:1
if (!("v" in index)) {
index["v"] = 1;
}
});
}
// Call the original function, with a potentially modified command object.
return clientFunction.apply(conn, makeFuncArgs(cmdObj));
}
// Override the default runCommand with our custom version.
OverrideHelpers.overrideRunCommand(runCommandOverride);