summaryrefslogtreecommitdiff
path: root/jstests/indexp.js
blob: d71de4716a7ff0308c8ef89976a11506e480becb (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
// Tests that SERVER-11374 is fixed: specifically, that indexes cannot
// be created on fields that begin with '$' but are not part of DBRefs
// and that indexes cannot be created on field paths that contain empty
// fields.

var coll = db.jstests_indexp;

// Empty field checks.
coll.ensureIndex({ 'a..b': 1 });
assert( db.getLastError() != null,
        "Expected error, but index on 'a..b' was created successfully." );

coll.ensureIndex({ '.a': 1 });
assert( db.getLastError() != null,
        "Expected error, but index on '.a' was created successfully." );

coll.ensureIndex({ 'a.': 1 });
assert( db.getLastError() != null,
        "Expected error, but index on 'a.' was created successfully." );

coll.ensureIndex({ '.': 1 });
assert( db.getLastError() != null,
        "Expected error, but index on '.' was created successfully." );

coll.ensureIndex({ '': 1 });
assert( db.getLastError() != null,
        "Expected error, but index on '' was created successfully." );

coll.ensureIndex({ 'a.b': 1 });
assert( db.getLastError() == null,
        "Expected no error, but creating index on 'a.b' failed." );

// '$'-prefixed field checks.
coll.ensureIndex({ '$a': 1 });
assert( db.getLastError() != null,
        "Expected error, but index on '$a' was created successfully." );

coll.ensureIndex({ 'a.$b': 1 });
assert( db.getLastError() != null,
        "Expected error, but index on 'a.$b' was created successfully." );

coll.ensureIndex({ 'a$ap': 1 });
assert( db.getLastError() == null,
        "Expected no error, but creating index on 'a$ap' failed." );

coll.ensureIndex({ '$db': 1 });
assert( db.getLastError() != null,
        "Expected error, but index on '$db' was created successfully." );

coll.ensureIndex({ 'a.$id': 1 });
assert( db.getLastError() == null,
        "Expected no error, but creating index on 'a.$id' failed." );

coll.dropIndexes();