@@ -44,9 +44,8 @@ createCollectionWithData = function (db, collectionName, dataGenerator) {
4444 numIndexes ++ ;
4545 }
4646
47- // Make sure we actually added all the indexes we thing we added. +1 for the _id index.
48- assert . eq ( db . system . indexes . find ( { "ns" : db . toString ( ) + "." + collection . getName ( ) } ) . count ( ) ,
49- numIndexes + 1 ) ;
47+ // Make sure we actually added all the indexes we think we added. +1 for the _id index.
48+ assert . eq ( collection . getIndexes ( ) . length , numIndexes + 1 ) ;
5049
5150 var numInserted = 0 ;
5251 while ( dataGenerator . data . hasNext ( ) ) {
@@ -78,7 +77,10 @@ function CollectionDataValidator() {
7877 this . recordCollectionData = function ( collection ) {
7978
8079 // Save the indexes for this collection for later comparison
81- indexData = collection . getDB ( ) . system . indexes . find ( { "ns" : collection . getFullName ( ) } ) . sort ( { "name" :1 } ) . toArray ( ) ;
80+ indexData = collection . getIndexes ( ) . sort ( function ( a , b ) {
81+ if ( a . name > b . name ) return 1 ;
82+ else return - 1 ;
83+ } ) ;
8284
8385 // Save the data for this collection for later comparison
8486 collectionData = collection . find ( ) . sort ( { "_id" :1 } ) . toArray ( ) ;
@@ -137,7 +139,10 @@ function CollectionDataValidator() {
137139 assert . docEq ( collectionStats , newCollectionStats , "collection metadata not equal" ) ;
138140
139141 // Get the indexes for this collection
140- var newIndexData = collection . getDB ( ) . system . indexes . find ( { "ns" : collection . getFullName ( ) } ) . sort ( { "name" :1 } ) . toArray ( ) ;
142+ var newIndexData = collection . getIndexes ( ) . sort ( function ( a , b ) {
143+ if ( a . name > b . name ) return 1 ;
144+ else return - 1 ;
145+ } ) ;
141146 for ( var i = 0 ; i < newIndexData . length ; i ++ ) {
142147 assert . docEq ( indexData [ i ] , newIndexData [ i ] , "indexes not equal" ) ;
143148 }
@@ -164,7 +169,7 @@ function collectionDataValidatorTests() {
164169 collection = createCollectionWithData ( db , "test" , myGenerator ) ;
165170 myValidator = new CollectionDataValidator ( ) ;
166171 myValidator . recordCollectionData ( collection ) ;
167- db . test . dropIndex ( db . system . indexes . findOne ( { " key.a" : { "$exists" : true } } ) . key ) ;
172+ db . test . dropIndex ( db . test . getIndexKeys ( ) . filter ( function ( key ) { return key . a != null } ) [ 0 ] ) ;
168173 assert . throws ( myValidator . validateCollectionData , [ collection ] , "Validation function should have thrown since we modified the collection" ) ;
169174
170175
@@ -186,7 +191,7 @@ function collectionDataValidatorTests() {
186191 collection = createCollectionWithData ( db , "test" , myGenerator ) ;
187192 myValidator = new CollectionDataValidator ( ) ;
188193 myValidator . recordCollectionData ( collection ) ;
189- db . test . dropIndex ( db . system . indexes . findOne ( { " key.a" : { "$exists" : true } } ) . key ) ;
194+ db . test . dropIndex ( db . test . getIndexKeys ( ) . filter ( function ( key ) { return key . a != null } ) [ 0 ] ) ;
190195 assert . throws ( myValidator . validateCollectionData , [ collection ] , "Validation function should have thrown since we modified the collection" ) ;
191196
192197
0 commit comments