From c694265d2d1f41a24a4497e4adaa580f45a59cde Mon Sep 17 00:00:00 2001 From: Lucas Hrabovsky Date: Thu, 4 Aug 2016 15:03:13 -0400 Subject: [PATCH] INT-1660: Fix TypeError: Cannot read property 'indexSizes' of undefined --- lib/fetch.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/fetch.js b/lib/fetch.js index 997f72b..4f1296b 100644 --- a/lib/fetch.js +++ b/lib/fetch.js @@ -9,7 +9,7 @@ var async = require('async'); var mongodbNS = require('mongodb-ns'); var isNotAuthorizedError = require('mongodb-js-errors').isNotAuthorized; -// var debug = require('debug')('mongodb-index-model:fetch'); +var debug = require('debug')('mongodb-index-model:fetch'); /** * helper function to attach objects to the async.auto task structure. @@ -88,8 +88,13 @@ function getIndexSizes(done, results) { var ns = mongodbNS(results.namespace); db.db(ns.database).collection(ns.collection).stats(function(err, res) { if (err) { - done(err); + if (isNotAuthorizedError(err)) { + debug('Not authorized to get collection stats. Returning default for indexSizes {}.'); + return done(null, {}); + } + return done(err); } + res = _.mapValues(res.indexSizes, function(size) { return {size: size}; });