File: indexapi.js

package info (click to toggle)
mongodb 1%3A2.0.6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 17,204 kB
  • sloc: cpp: 109,783; ansic: 101,073; python: 2,287; perl: 395; makefile: 370; sh: 242; asm: 46
file content (40 lines) | stat: -rw-r--r-- 1,228 bytes parent folder | download | duplicates (4)
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

t = db.indexapi;
t.drop();

key = { x : 1 };

c = { ns : t._fullName , key : key , name : t._genIndexName( key ) };
assert.eq( c , t._indexSpec( { x : 1 } ) , "A" );

c.name = "bob";
assert.eq( c , t._indexSpec( { x : 1 } , "bob" ) , "B" );

c.name = t._genIndexName( key );
assert.eq( c , t._indexSpec( { x : 1 } ) , "C" );

c.unique = true;
assert.eq( c , t._indexSpec( { x : 1 } , true ) , "D" );
assert.eq( c , t._indexSpec( { x : 1 } , [ true ] ) , "E" );
assert.eq( c , t._indexSpec( { x : 1 } , { unique : true } ) , "F" );

c.dropDups = true;
assert.eq( c , t._indexSpec( { x : 1 } , [ true , true ] ) , "G" );
assert.eq( c , t._indexSpec( { x : 1 } , { unique : true , dropDups : true } ) , "F" );

t.ensureIndex( { x : 1 } , { unique : true } );
idx = t.getIndexes();
assert.eq( 2 , idx.length , "M1" );
assert.eq( key , idx[1].key , "M2" );
assert( idx[1].unique , "M3" );

t.drop();
t.ensureIndex( { x : 1 } , { unique : 1 } );
idx = t.getIndexes();
assert.eq( 2 , idx.length , "M1" );
assert.eq( key , idx[1].key , "M2" );
assert( idx[1].unique , "M3" );
//printjson( idx );

db.system.indexes.insert( { ns : "test" , key : { x : 1 } , name : "x" } );
assert( db.getLastError().indexOf( "invalid" ) >= 0 , "Z1" );