@@ -526,24 +526,38 @@ Db.prototype.dropIndex = function(collectionName, indexName, callback) {
526526/**
527527 Index Information
528528**/
529- Db . prototype . indexInformation = function ( collectionName , callback ) {
530- if ( typeof collectionName === "function" ) { callback = collectionName ; collectionName = null ; }
529+ Db . prototype . indexInformation = function ( collectionName , options , callback ) {
530+ // Unpack calls
531+ var args = Array . prototype . slice . call ( arguments , 0 ) ;
532+ callback = args . pop ( ) ;
533+ collectionName = args . length ? args . shift ( ) : null ;
534+ options = args . length ? args . shift ( ) : { } ;
535+
536+ // If we specified full information
537+ var full = options [ 'full' ] == null ? false : options [ 'full' ] ;
531538 // Build selector for the indexes
532539 var selector = collectionName != null ? { ns : ( this . databaseName + "." + collectionName ) } : { } ;
533- var info = { } ;
534540 // Iterate through all the fields of the index
535- new Cursor ( this , new Collection ( this , DbCommand . SYSTEM_INDEX_COLLECTION ) , selector ) . each ( function ( err , index ) {
541+ new Cursor ( this , new Collection ( this , DbCommand . SYSTEM_INDEX_COLLECTION ) , selector ) . toArray ( function ( err , indexes ) {
536542 if ( err != null ) return callback ( err , null ) ;
543+ // Contains all the information
544+ var info = { } ;
537545
538- // Return the info when finished
539- if ( index == null ) {
540- callback ( null , info ) ;
541- } else {
546+ // if full defined just return all the indexes directly
547+ if ( full ) return callback ( null , indexes ) ;
548+
549+ // Process all the indexes
550+ for ( var i = 0 ; i < indexes . length ; i ++ ) {
551+ var index = indexes [ i ] ;
552+ // Let's unpack the object
542553 info [ index . name ] = [ ] ;
543554 for ( var name in index . key ) {
544555 info [ index . name ] . push ( [ name , index . key [ name ] ] ) ;
545556 }
546557 }
558+
559+ // Return all the indexes
560+ callback ( null , info ) ;
547561 } ) ;
548562} ;
549563
0 commit comments