@@ -417,6 +417,15 @@ export default class ShellInstanceState {
417
417
this . evaluationListener = listener ;
418
418
}
419
419
420
+ public _getMongoByConnectionId ( connectionId : string ) : Mongo {
421
+ for ( const mongo of this . mongos ) {
422
+ if ( connectionIdFromURI ( mongo . getURI ( ) ) === connectionId ) {
423
+ return mongo ;
424
+ }
425
+ }
426
+ throw new Error ( `mongo with connection id ${ connectionId } not found` ) ;
427
+ }
428
+
420
429
public getAutocompletionContext ( ) : AutocompletionContext {
421
430
return {
422
431
currentDatabaseAndConnection : ( ) => {
@@ -425,12 +434,12 @@ export default class ShellInstanceState {
425
434
databaseName : this . currentDb . getName ( ) ,
426
435
} ;
427
436
} ,
428
- databasesForConnection : async ( ) : //connectionId: string,
429
- Promise < string [ ] > => {
437
+ databasesForConnection : async (
438
+ connectionId : string
439
+ ) : Promise < string [ ] > => {
440
+ const mongo = this . _getMongoByConnectionId ( connectionId ) ;
430
441
try {
431
- // TODO: use connectionId
432
- const dbNames =
433
- await this . currentDb . _mongo . _getDatabaseNamesForCompletion ( ) ;
442
+ const dbNames = await mongo . _getDatabaseNamesForCompletion ( ) ;
434
443
return dbNames . filter ( ( name ) => ! CONTROL_CHAR_REGEXP . test ( name ) ) ;
435
444
} catch ( err : any ) {
436
445
if (
@@ -442,13 +451,15 @@ export default class ShellInstanceState {
442
451
throw err ;
443
452
}
444
453
} ,
445
- collectionsForDatabase : async ( ) : //connectionId: string,
446
- //databaseName: string
447
- Promise < string [ ] > => {
454
+ collectionsForDatabase : async (
455
+ connectionId : string ,
456
+ databaseName : string
457
+ ) : Promise < string [ ] > => {
458
+ const mongo = this . _getMongoByConnectionId ( connectionId ) ;
448
459
try {
449
- // TODO: use connectionId and databaseName
450
- const collectionNames =
451
- await this . currentDb . _getCollectionNamesForCompletion ( ) ;
460
+ const collectionNames = await mongo
461
+ . _getDb ( databaseName )
462
+ . _getCollectionNamesForCompletion ( ) ;
452
463
return collectionNames . filter (
453
464
( name ) => ! CONTROL_CHAR_REGEXP . test ( name )
454
465
) ;
@@ -463,11 +474,13 @@ export default class ShellInstanceState {
463
474
}
464
475
} ,
465
476
schemaInformationForCollection : async (
466
- connectionKey : string ,
477
+ connectionId : string ,
467
478
databaseName : string ,
468
479
collectionName : string
469
480
) : Promise < JSONSchema > => {
470
- const docs = await this . currentDb
481
+ const mongo = this . _getMongoByConnectionId ( connectionId ) ;
482
+ const docs = await mongo
483
+ . _getDb ( databaseName )
471
484
. getCollection ( collectionName )
472
485
. _getSampleDocsForCompletion ( ) ;
473
486
const schemaAccessor = await analyzeDocuments ( docs ) ;
0 commit comments