@@ -8,15 +8,9 @@ var _ = require('lodash');
88var async = require ( 'async' ) ;
99var mongodbNS = require ( 'mongodb-ns' ) ;
1010var isNotAuthorizedError = require ( 'mongodb-js-errors' ) . isNotAuthorized ;
11- var ReadPreference = require ( 'mongodb' ) . ReadPreference ;
1211
1312var debug = require ( 'debug' ) ( 'mongodb-index-model:fetch' ) ;
1413
15- /**
16- * The default read preference.
17- */
18- var READ = ReadPreference . PRIMARY_PREFERRED ;
19-
2014/**
2115 * helper function to attach objects to the async.auto task structure.
2216 * @param {any } anything pass in any variable to attach it to the name
@@ -34,7 +28,7 @@ function attach(anything, done) {
3428function getIndexes ( done , results ) {
3529 var db = results . db ;
3630 var ns = mongodbNS ( results . namespace ) ;
37- db . db ( ns . database , { readPreference : { mode : READ } , returnNonCachedInstance : true } ) . collection ( ns . collection ) . indexes ( function ( err , indexes ) {
31+ db . db ( ns . database , { returnNonCachedInstance : true } ) . collection ( ns . collection ) . indexes ( function ( err , indexes ) {
3832 if ( err ) {
3933 done ( err ) ;
4034 }
@@ -58,8 +52,8 @@ function getIndexStats(done, results) {
5852 { $indexStats : { } } ,
5953 { $project : { name : 1 , usageHost : '$host' , usageCount : '$accesses.ops' , usageSince : '$accesses.since' } }
6054 ] ;
61- var collection = db . db ( ns . database , { readPreference : { mode : READ } , returnNonCachedInstance : true } ) . collection ( ns . collection ) ;
62- collection . aggregate ( pipeline , function ( err , res ) {
55+ var collection = db . db ( ns . database , { returnNonCachedInstance : true } ) . collection ( ns . collection ) ;
56+ collection . aggregate ( pipeline , { cursor : { } } ) . toArray ( function ( err , res ) {
6357 if ( err ) {
6458 if ( isNotAuthorizedError ( err ) ) {
6559 /**
@@ -92,7 +86,7 @@ function getIndexStats(done, results) {
9286function getIndexSizes ( done , results ) {
9387 var db = results . db ;
9488 var ns = mongodbNS ( results . namespace ) ;
95- db . db ( ns . database , { readPreference : { mode : READ } , returnNonCachedInstance : true } ) . collection ( ns . collection ) . stats ( function ( err , res ) {
89+ db . db ( ns . database , { returnNonCachedInstance : true } ) . collection ( ns . collection ) . stats ( function ( err , res ) {
9690 if ( err ) {
9791 if ( isNotAuthorizedError ( err ) ) {
9892 debug ( 'Not authorized to get collection stats. Returning default for indexSizes {}.' ) ;
0 commit comments