@@ -438,12 +438,8 @@ var Db = function(databaseName, topology, options) {
438
438
if ( err ) return fallbackListCollections ( ) ;
439
439
// List of result documents that have been filtered
440
440
var filtered_documents = result . collections . filter ( function ( document ) {
441
- if ( name && document . name != name ) {
442
- return false ;
443
- } else if ( document . name . indexOf ( '$' ) != - 1 ) {
444
- return false ;
445
- }
446
-
441
+ if ( name && document . name != name ) return false ;
442
+ if ( document . name . indexOf ( '$' ) != - 1 ) return false ;
447
443
return true ;
448
444
} ) ;
449
445
@@ -1127,23 +1123,11 @@ var Db = function(databaseName, topology, options) {
1127
1123
1128
1124
// If we specified full information
1129
1125
var full = options [ 'full' ] == null ? false : options [ 'full' ] ;
1130
- // Build selector for the indexes
1131
- var selector = name != null ? { ns : ( databaseName + "." + name ) } : { } ;
1132
1126
1133
- // Get read preference if we set one
1134
- readPreference = ReadPreference . PRIMARY ;
1135
-
1136
- // Iterate through all the fields of the index
1137
- var collection = this . collection ( Db . SYSTEM_INDEX_COLLECTION ) ;
1138
- // Perform the find for the collection
1139
- collection . find ( selector ) . setReadPreference ( readPreference ) . toArray ( function ( err , indexes ) {
1140
- if ( err != null ) return handleCallback ( callback , err , null ) ;
1127
+ // Process all the results from the index command and collection
1128
+ var processResults = function ( indexes ) {
1141
1129
// Contains all the information
1142
1130
var info = { } ;
1143
-
1144
- // if full defined just return all the indexes directly
1145
- if ( full ) return handleCallback ( callback , null , indexes ) ;
1146
-
1147
1131
// Process all the indexes
1148
1132
for ( var i = 0 ; i < indexes . length ; i ++ ) {
1149
1133
var index = indexes [ i ] ;
@@ -1154,8 +1138,36 @@ var Db = function(databaseName, topology, options) {
1154
1138
}
1155
1139
}
1156
1140
1141
+ return info ;
1142
+ }
1143
+
1144
+ // Fallback to pre 2.8 getting the index information
1145
+ var fallbackListIndexes = function ( ) {
1146
+ // Build selector for the indexes
1147
+ var selector = name != null ? { ns : ( databaseName + "." + name ) } : { } ;
1148
+
1149
+ // Get read preference if we set one
1150
+ readPreference = ReadPreference . PRIMARY ;
1151
+
1152
+ // Iterate through all the fields of the index
1153
+ var collection = self . collection ( Db . SYSTEM_INDEX_COLLECTION ) ;
1154
+ // Perform the find for the collection
1155
+ collection . find ( selector ) . setReadPreference ( readPreference ) . toArray ( function ( err , indexes ) {
1156
+ if ( err != null ) return handleCallback ( callback , err , null ) ;
1157
+ // if full defined just return all the indexes directly
1158
+ if ( full ) return handleCallback ( callback , null , indexes ) ;
1159
+ // Return all the indexes
1160
+ handleCallback ( callback , null , processResults ( indexes ) ) ;
1161
+ } ) ;
1162
+ }
1163
+
1164
+ // Attempt to execute the listIndexes command
1165
+ self . command ( { listIndexes : name } , function ( err , result ) {
1166
+ if ( err ) return fallbackListIndexes ( ) ;
1167
+ // if full defined just return all the indexes directly
1168
+ if ( full ) return handleCallback ( callback , null , result . indexes ) ;
1157
1169
// Return all the indexes
1158
- handleCallback ( callback , null , info ) ;
1170
+ handleCallback ( callback , null , processResults ( result . indexes ) ) ;
1159
1171
} ) ;
1160
1172
} ;
1161
1173
0 commit comments