@@ -28,16 +28,19 @@ function attach(anything, done) {
28
28
function getIndexes ( done , results ) {
29
29
var client = results . client ;
30
30
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 ) ;
38
43
} ) ;
39
- done ( null , indexes ) ;
40
- } ) ;
41
44
}
42
45
43
46
/**
@@ -49,11 +52,18 @@ function getIndexStats(done, results) {
49
52
var client = results . client ;
50
53
var ns = mongodbNS ( results . namespace ) ;
51
54
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
+ }
54
64
] ;
55
65
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 ) {
57
67
if ( err ) {
58
68
if ( isNotAuthorizedError ( err ) ) {
59
69
/**
@@ -86,20 +96,25 @@ function getIndexStats(done, results) {
86
96
function getIndexSizes ( done , results ) {
87
97
var client = results . client ;
88
98
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 ) ;
94
111
}
95
- return done ( err ) ;
96
- }
97
112
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 ) ;
100
117
} ) ;
101
- done ( null , res ) ;
102
- } ) ;
103
118
}
104
119
105
120
/**
@@ -120,7 +135,7 @@ function combineStatsAndIndexes(done, results) {
120
135
121
136
/**
122
137
* 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
124
139
* @param {String } namespace namespace for which to get indexes
125
140
* @param {Function } done callback
126
141
*/
@@ -131,7 +146,12 @@ function getIndexDetails(client, namespace, done) {
131
146
getIndexes : [ 'client' , 'namespace' , getIndexes ] ,
132
147
getIndexStats : [ 'client' , 'namespace' , getIndexStats ] ,
133
148
getIndexSizes : [ 'client' , 'namespace' , getIndexSizes ] ,
134
- indexes : [ 'getIndexes' , 'getIndexStats' , 'getIndexSizes' , combineStatsAndIndexes ]
149
+ indexes : [
150
+ 'getIndexes' ,
151
+ 'getIndexStats' ,
152
+ 'getIndexSizes' ,
153
+ combineStatsAndIndexes
154
+ ]
135
155
} ;
136
156
137
157
async . auto ( tasks , function ( err , results ) {
@@ -144,5 +164,4 @@ function getIndexDetails(client, namespace, done) {
144
164
} ) ;
145
165
}
146
166
147
-
148
167
module . exports = getIndexDetails ;
0 commit comments