Skip to content

Commit 5ccc158

Browse files
authored
feat(shell-api): make db/coll autocompletions case-insensitive MONGOSH-847 (#1128)
1 parent e46bb7a commit 5ccc158

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/shell-api/src/integration.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,8 +2146,10 @@ describe('Shell API (integration)', function() {
21462146
expect(params.connectionInfo().is_localhost).to.equal(true);
21472147
expect(await database._getCollectionNames()).to.deep.equal(['docs']);
21482148
expect(await params.getCollectionCompletionsForCurrentDb('d')).to.deep.equal(['docs']);
2149+
expect(await params.getCollectionCompletionsForCurrentDb('D')).to.deep.equal(['docs']);
21492150
expect(await params.getCollectionCompletionsForCurrentDb('e')).to.deep.equal([]);
21502151
expect(await params.getDatabaseCompletions('test-')).to.deep.equal([database.getName()]);
2152+
expect(await params.getDatabaseCompletions('TEST-')).to.deep.equal([database.getName()]);
21512153
});
21522154
});
21532155
});

packages/shell-api/src/shell-instance-state.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ export default class ShellInstanceState {
342342
getCollectionCompletionsForCurrentDb: async(collName: string): Promise<string[]> => {
343343
try {
344344
const collectionNames = await this.currentDb._getCollectionNamesForCompletion();
345-
return collectionNames.filter((name) => name.startsWith(collName));
345+
return collectionNames.filter((name) =>
346+
name.toLowerCase().startsWith(collName.toLowerCase()));
346347
} catch (err) {
347348
if (
348349
err.code === ShellApiErrors.NotConnected ||
@@ -356,7 +357,8 @@ export default class ShellInstanceState {
356357
getDatabaseCompletions: async(dbName: string): Promise<string[]> => {
357358
try {
358359
const dbNames = await this.currentDb._mongo._getDatabaseNamesForCompletion();
359-
return dbNames.filter((name) => name.startsWith(dbName));
360+
return dbNames.filter((name) =>
361+
name.toLowerCase().startsWith(dbName.toLowerCase()));
360362
} catch (err) {
361363
if (
362364
err.code === ShellApiErrors.NotConnected ||

0 commit comments

Comments
 (0)