@@ -417,6 +417,15 @@ export default class ShellInstanceState {
417417 this . evaluationListener = listener ;
418418 }
419419
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+
420429 public getAutocompletionContext ( ) : AutocompletionContext {
421430 return {
422431 currentDatabaseAndConnection : ( ) => {
@@ -425,12 +434,12 @@ export default class ShellInstanceState {
425434 databaseName : this . currentDb . getName ( ) ,
426435 } ;
427436 } ,
428- databasesForConnection : async ( ) : //connectionId: string,
429- Promise < string [ ] > => {
437+ databasesForConnection : async (
438+ connectionId : string
439+ ) : Promise < string [ ] > => {
440+ const mongo = this . _getMongoByConnectionId ( connectionId ) ;
430441 try {
431- // TODO: use connectionId
432- const dbNames =
433- await this . currentDb . _mongo . _getDatabaseNamesForCompletion ( ) ;
442+ const dbNames = await mongo . _getDatabaseNamesForCompletion ( ) ;
434443 return dbNames . filter ( ( name ) => ! CONTROL_CHAR_REGEXP . test ( name ) ) ;
435444 } catch ( err : any ) {
436445 if (
@@ -442,13 +451,15 @@ export default class ShellInstanceState {
442451 throw err ;
443452 }
444453 } ,
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 ) ;
448459 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 ( ) ;
452463 return collectionNames . filter (
453464 ( name ) => ! CONTROL_CHAR_REGEXP . test ( name )
454465 ) ;
@@ -463,11 +474,13 @@ export default class ShellInstanceState {
463474 }
464475 } ,
465476 schemaInformationForCollection : async (
466- connectionKey : string ,
477+ connectionId : string ,
467478 databaseName : string ,
468479 collectionName : string
469480 ) : Promise < JSONSchema > => {
470- const docs = await this . currentDb
481+ const mongo = this . _getMongoByConnectionId ( connectionId ) ;
482+ const docs = await mongo
483+ . _getDb ( databaseName )
471484 . getCollection ( collectionName )
472485 . _getSampleDocsForCompletion ( ) ;
473486 const schemaAccessor = await analyzeDocuments ( docs ) ;
0 commit comments