@@ -170,7 +170,7 @@ export function processDigestPassword(
170
170
* @param configDB
171
171
* @param verbose
172
172
*/
173
- export async function getPrintableShardStatus ( db : Database , verbose : boolean ) : Promise < any > {
173
+ export async function getPrintableShardStatus ( db : Database , verbose : boolean ) : Promise < Document > {
174
174
const result = { } as any ; // use array to maintain order
175
175
176
176
// configDB is a DB object that contains the sharding metadata of interest.
@@ -185,8 +185,8 @@ export async function getPrintableShardStatus(db: Database, verbose: boolean): P
185
185
186
186
const [ version , shards , mostRecentMongos ] = await Promise . all ( [
187
187
versionColl . findOne ( ) ,
188
- shardsColl . find ( ) . sort ( { _id : 1 } ) . toArray ( ) ,
189
- mongosColl . find ( ) . sort ( { ping : - 1 } ) . limit ( 1 ) . tryNext ( )
188
+ shardsColl . find ( ) . then ( cursor => cursor . sort ( { _id : 1 } ) . toArray ( ) ) ,
189
+ mongosColl . find ( ) . then ( cursor => cursor . sort ( { ping : - 1 } ) . limit ( 1 ) . tryNext ( ) )
190
190
] ) ;
191
191
if ( version === null ) {
192
192
throw new MongoshInvalidInputError (
@@ -228,8 +228,8 @@ export async function getPrintableShardStatus(db: Database, verbose: boolean): P
228
228
} ;
229
229
230
230
if ( verbose ) {
231
- result [ mongosAdjective ] = await mongosColl
232
- . find ( recentMongosQuery )
231
+ result [ mongosAdjective ] = await ( await mongosColl
232
+ . find ( recentMongosQuery ) )
233
233
. sort ( { ping : - 1 } )
234
234
. toArray ( ) ;
235
235
} else {
@@ -277,7 +277,7 @@ export async function getPrintableShardStatus(db: Database, verbose: boolean): P
277
277
( async ( ) : Promise < void > => {
278
278
// Output the list of active migrations
279
279
type Lock = { _id : string ; when : Date } ;
280
- const activeLocks : Lock [ ] = await configDB . getCollection ( 'locks' ) . find ( { state : { $eq : 2 } } ) . toArray ( ) as Lock [ ] ;
280
+ const activeLocks : Lock [ ] = await ( await configDB . getCollection ( 'locks' ) . find ( { state : { $eq : 2 } } ) ) . toArray ( ) as Lock [ ] ;
281
281
if ( activeLocks ?. length > 0 ) {
282
282
balancerRes [ 'Collections with active migrations' ] = activeLocks . map ( ( lock ) => {
283
283
return `${ lock . _id } started at ${ lock . when } ` ;
@@ -300,7 +300,7 @@ export async function getPrintableShardStatus(db: Database, verbose: boolean): P
300
300
301
301
if ( versionHasActionlog ) {
302
302
// Review config.actionlog for errors
303
- const balErrs = await configDB . getCollection ( 'actionlog' ) . find ( { what : 'balancer.round' } ) . sort ( { time : - 1 } ) . limit ( 5 ) . toArray ( ) ;
303
+ const balErrs = await ( await configDB . getCollection ( 'actionlog' ) . find ( { what : 'balancer.round' } ) ) . sort ( { time : - 1 } ) . limit ( 5 ) . toArray ( ) ;
304
304
const actionReport = { count : 0 , lastErr : '' , lastTime : ' ' } ;
305
305
if ( balErrs !== null ) {
306
306
balErrs . forEach ( ( r : any ) => {
@@ -393,7 +393,7 @@ export async function getPrintableShardStatus(db: Database, verbose: boolean): P
393
393
const dbRes : any [ ] = [ ] ;
394
394
result . databases = dbRes ;
395
395
396
- const databases = await configDB . getCollection ( 'databases' ) . find ( ) . sort ( { name : 1 } ) . toArray ( ) ;
396
+ const databases = await ( await configDB . getCollection ( 'databases' ) . find ( ) ) . sort ( { name : 1 } ) . toArray ( ) ;
397
397
398
398
// Special case the config db, since it doesn't have a record in config.databases.
399
399
databases . push ( { '_id' : 'config' , 'primary' : 'config' , 'partitioned' : true } ) ;
@@ -405,8 +405,8 @@ export async function getPrintableShardStatus(db: Database, verbose: boolean): P
405
405
const escapeRegex = ( string : string ) : string => {
406
406
return string . replace ( / [ - \/ \\ ^ $ * + ? . ( ) | [ \] { } ] / g, '\\$&' ) ;
407
407
} ;
408
- const colls = await configDB . getCollection ( 'collections' )
409
- . find ( { _id : new RegExp ( '^' + escapeRegex ( db . _id ) + '\\.' ) } )
408
+ const colls = await ( await configDB . getCollection ( 'collections' )
409
+ . find ( { _id : new RegExp ( '^' + escapeRegex ( db . _id ) + '\\.' ) } ) )
410
410
. sort ( { _id : 1 } )
411
411
. toArray ( ) ;
412
412
@@ -441,45 +441,39 @@ export async function getPrintableShardStatus(db: Database, verbose: boolean): P
441
441
442
442
// NOTE: this will return the chunk info as a string, and will print ugly BSON
443
443
if ( totalChunks < 20 || verbose ) {
444
- ( await chunksColl . find ( chunksCollMatch )
445
- . sort ( { min : 1 } ) . toArray ( ) )
446
- . forEach ( ( chunk : any ) => {
447
- const c = {
448
- min : chunk . min ,
449
- max : chunk . max ,
450
- 'on shard' : chunk . shard ,
451
- 'last modified' : chunk . lastmod
452
- } as any ;
453
- // Displaying a full, multi-line output for each chunk is a bit verbose,
454
- // even if there are only a few chunks. Where supported, we use a custom
455
- // inspection function to inspect a copy of this object with an unlimited
456
- // line break length (i.e. all objects on a single line).
457
- Object . defineProperty ( c , Symbol . for ( 'nodejs.util.inspect.custom' ) , {
458
- value : function ( depth : number , options : any ) : string {
459
- return inspect ( { ...this } , { ...options , breakLength : Infinity } ) ;
460
- } ,
461
- writable : true ,
462
- configurable : true
463
- } ) ;
464
- if ( chunk . jumbo ) c . jumbo = 'yes' ;
465
- chunksRes . push ( c ) ;
444
+ for await ( const chunk of ( await chunksColl . find ( chunksCollMatch ) ) . sort ( { min : 1 } ) ) {
445
+ const c = {
446
+ min : chunk . min ,
447
+ max : chunk . max ,
448
+ 'on shard' : chunk . shard ,
449
+ 'last modified' : chunk . lastmod
450
+ } as any ;
451
+ // Displaying a full, multi-line output for each chunk is a bit verbose,
452
+ // even if there are only a few chunks. Where supported, we use a custom
453
+ // inspection function to inspect a copy of this object with an unlimited
454
+ // line break length (i.e. all objects on a single line).
455
+ Object . defineProperty ( c , Symbol . for ( 'nodejs.util.inspect.custom' ) , {
456
+ value : function ( depth : number , options : any ) : string {
457
+ return inspect ( { ...this } , { ...options , breakLength : Infinity } ) ;
458
+ } ,
459
+ writable : true ,
460
+ configurable : true
466
461
} ) ;
462
+ if ( chunk . jumbo ) c . jumbo = 'yes' ;
463
+ chunksRes . push ( c ) ;
464
+ }
467
465
} else {
468
466
chunksRes . push ( 'too many chunks to print, use verbose if you want to force print' ) ;
469
467
}
470
468
471
469
const tagsRes : any [ ] = [ ] ;
472
- ( await configDB . getCollection ( 'tags' )
473
- . find ( chunksCollMatch )
474
- . sort ( { min : 1 } )
475
- . toArray ( ) )
476
- . forEach ( ( tag : any ) => {
477
- tagsRes . push ( {
478
- tag : tag . tag ,
479
- min : tag . min ,
480
- max : tag . max
481
- } ) ;
470
+ for await ( const tag of ( await configDB . getCollection ( 'tags' ) . find ( chunksCollMatch ) ) . sort ( { min : 1 } ) ) {
471
+ tagsRes . push ( {
472
+ tag : tag . tag ,
473
+ min : tag . min ,
474
+ max : tag . max
482
475
} ) ;
476
+ }
483
477
collRes . chunks = chunksRes ;
484
478
collRes . tags = tagsRes ;
485
479
return [ coll . _id , collRes ] ;
0 commit comments