Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.

Commit 16a9f9f

Browse files
imlucaskangas
authored andcommitted
INT-1660: Fix TypeError: Cannot read property 'indexSizes' of undefined (#36)
1 parent 2385e0c commit 16a9f9f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/fetch.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var async = require('async');
99
var mongodbNS = require('mongodb-ns');
1010
var isNotAuthorizedError = require('mongodb-js-errors').isNotAuthorized;
1111

12-
// var debug = require('debug')('mongodb-index-model:fetch');
12+
var debug = require('debug')('mongodb-index-model:fetch');
1313

1414
/**
1515
* helper function to attach objects to the async.auto task structure.
@@ -88,8 +88,13 @@ function getIndexSizes(done, results) {
8888
var ns = mongodbNS(results.namespace);
8989
db.db(ns.database).collection(ns.collection).stats(function(err, res) {
9090
if (err) {
91-
done(err);
91+
if (isNotAuthorizedError(err)) {
92+
debug('Not authorized to get collection stats. Returning default for indexSizes {}.');
93+
return done(null, {});
94+
}
95+
return done(err);
9296
}
97+
9398
res = _.mapValues(res.indexSizes, function(size) {
9499
return {size: size};
95100
});

0 commit comments

Comments
 (0)