@@ -28,16 +28,19 @@ function attach(anything, done) {
2828function getIndexes ( done , results ) {
2929 var client = results . client ;
3030 var ns = mongodbNS ( results . namespace ) ;
31- client . db ( ns . database ) . collection ( ns . collection ) . indexes ( function ( err , indexes ) {
32- if ( err ) {
33- done ( err ) ;
34- }
35- // add ns field to each index
36- _ . each ( indexes , function ( idx ) {
37- idx . ns = ns . ns ;
31+ client
32+ . db ( ns . database )
33+ . collection ( ns . collection )
34+ . indexes ( function ( err , indexes ) {
35+ if ( err ) {
36+ done ( err ) ;
37+ }
38+ // add ns field to each index
39+ _ . each ( indexes , function ( idx ) {
40+ idx . ns = ns . ns ;
41+ } ) ;
42+ done ( null , indexes ) ;
3843 } ) ;
39- done ( null , indexes ) ;
40- } ) ;
4144}
4245
4346/**
@@ -49,11 +52,18 @@ function getIndexStats(done, results) {
4952 var client = results . client ;
5053 var ns = mongodbNS ( results . namespace ) ;
5154 var pipeline = [
52- { $indexStats : { } } ,
53- { $project : { name : 1 , usageHost : '$host' , usageCount : '$accesses.ops' , usageSince : '$accesses.since' } }
55+ { $indexStats : { } } ,
56+ {
57+ $project : {
58+ name : 1 ,
59+ usageHost : '$host' ,
60+ usageCount : '$accesses.ops' ,
61+ usageSince : '$accesses.since'
62+ }
63+ }
5464 ] ;
5565 var collection = client . db ( ns . database ) . collection ( ns . collection ) ;
56- collection . aggregate ( pipeline , { cursor : { } } ) . toArray ( function ( err , res ) {
66+ collection . aggregate ( pipeline , { cursor : { } } ) . toArray ( function ( err , res ) {
5767 if ( err ) {
5868 if ( isNotAuthorizedError ( err ) ) {
5969 /**
@@ -86,20 +96,25 @@ function getIndexStats(done, results) {
8696function getIndexSizes ( done , results ) {
8797 var client = results . client ;
8898 var ns = mongodbNS ( results . namespace ) ;
89- client . db ( ns . database ) . collection ( ns . collection ) . stats ( function ( err , res ) {
90- if ( err ) {
91- if ( isNotAuthorizedError ( err ) ) {
92- debug ( 'Not authorized to get collection stats. Returning default for indexSizes {}.' ) ;
93- return done ( null , { } ) ;
99+ client
100+ . db ( ns . database )
101+ . collection ( ns . collection )
102+ . stats ( function ( err , res ) {
103+ if ( err ) {
104+ if ( isNotAuthorizedError ( err ) ) {
105+ debug (
106+ 'Not authorized to get collection stats. Returning default for indexSizes {}.'
107+ ) ;
108+ return done ( null , { } ) ;
109+ }
110+ return done ( err ) ;
94111 }
95- return done ( err ) ;
96- }
97112
98- res = _ . mapValues ( res . indexSizes , function ( size ) {
99- return { size : size } ;
113+ res = _ . mapValues ( res . indexSizes , function ( size ) {
114+ return { size : size } ;
115+ } ) ;
116+ done ( null , res ) ;
100117 } ) ;
101- done ( null , res ) ;
102- } ) ;
103118}
104119
105120/**
@@ -120,7 +135,7 @@ function combineStatsAndIndexes(done, results) {
120135
121136/**
122137 * get basic index information via `db.collection.indexes()`
123- * @param {MongoClient } db db handle from mongodb driver
138+ * @param {MongoClient } client handle from mongodb driver
124139 * @param {String } namespace namespace for which to get indexes
125140 * @param {Function } done callback
126141 */
@@ -131,7 +146,12 @@ function getIndexDetails(client, namespace, done) {
131146 getIndexes : [ 'client' , 'namespace' , getIndexes ] ,
132147 getIndexStats : [ 'client' , 'namespace' , getIndexStats ] ,
133148 getIndexSizes : [ 'client' , 'namespace' , getIndexSizes ] ,
134- indexes : [ 'getIndexes' , 'getIndexStats' , 'getIndexSizes' , combineStatsAndIndexes ]
149+ indexes : [
150+ 'getIndexes' ,
151+ 'getIndexStats' ,
152+ 'getIndexSizes' ,
153+ combineStatsAndIndexes
154+ ]
135155 } ;
136156
137157 async . auto ( tasks , function ( err , results ) {
@@ -144,5 +164,4 @@ function getIndexDetails(client, namespace, done) {
144164 } ) ;
145165}
146166
147-
148167module . exports = getIndexDetails ;
0 commit comments