summaryrefslogtreecommitdiff
path: root/jstests/core/index_plugins.js
blob: d7271217e2f98046267fadf4b433cebec014f441 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Test creation of compound indexes with special index types.

var coll = db.index_plugins;
coll.drop();

// Test building special index types on a single field.

assert.commandWorked(coll.ensureIndex({a: "hashed"}));
coll.dropIndexes();
assert.commandWorked(coll.ensureIndex({a: "2d"}));
coll.dropIndexes();
assert.commandWorked(coll.ensureIndex({a: "2dsphere"}));
coll.dropIndexes();
assert.commandWorked(coll.ensureIndex({a: "text"}));
coll.dropIndexes();

assert.commandFailed(coll.ensureIndex({a: "geoHaystack"}, {bucketSize: 1})); // compound required

// Test compounding special index types with an ascending index. 

assert.commandWorked(coll.ensureIndex({a: "2dsphere", b: 1}));
coll.dropIndexes();
assert.commandWorked(coll.ensureIndex({a: 1, b: "2dsphere"}));
coll.dropIndexes();

assert.commandWorked(coll.ensureIndex({a: "text", b: 1}));
coll.dropIndexes();
assert.commandWorked(coll.ensureIndex({a: 1, b: "text"}));
coll.dropIndexes();

assert.commandWorked(coll.ensureIndex({a: "2d", b: 1}));
coll.dropIndexes();
assert.commandFailed(coll.ensureIndex({a: 1, b: "2d"})); // unsupported

assert.commandWorked(coll.ensureIndex({a: "geoHaystack", b: 1}, {bucketSize: 1}));
coll.dropIndexes();
assert.commandFailed(coll.ensureIndex({a: 1, b: "geoHaystack"}, {bucketSize: 1})); // unsupported

assert.commandFailed(coll.ensureIndex({a: "hashed", b: 1})); // unsupported
assert.commandFailed(coll.ensureIndex({a: 1, b: "hashed"})); // unsupported

// Test compound index where multiple fields have same special index type.

assert.commandWorked(coll.ensureIndex({a: "2dsphere", b: "2dsphere"}));
coll.dropIndexes();
assert.commandWorked(coll.ensureIndex({a: "text", b: "text"}));
coll.dropIndexes();

assert.commandFailed(coll.ensureIndex({a: "2d", b: "2d"})); // unsupported
assert.commandFailed(coll.ensureIndex({a: "geoHaystack", b: "geoHaystack"}, // unsupported
                                      {bucketSize: 1}));

assert.commandFailed(coll.ensureIndex({a: "hashed", b: "hashed"})); // unsupported

// Test compounding different special index types with each other.

assert.commandFailed(coll.ensureIndex({a: "2d", b: "hashed"})); // unsupported
assert.commandFailed(coll.ensureIndex({a: "hashed", b: "2dsphere"})); // unsupported
assert.commandFailed(coll.ensureIndex({a: "2dsphere", b: "text"})); // unsupported
assert.commandFailed(coll.ensureIndex({a: "text", b: "geoHaystack"})); // unsupported
assert.commandFailed(coll.ensureIndex({a: "geoHaystack", b: "2d"}, // unsupported
                                      {bucketSize: 1}));