Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/cli-repl/test/e2e-direct.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ describe('e2e direct connection', () => {
});

context('after rs.initiate()', () => {
let dbname: string;

before(async() => {
const replSetConfig = {
_id: replSetId,
Expand All @@ -50,6 +52,15 @@ describe('e2e direct connection', () => {
shell.assertContainsOutput(`me: '${await rs0.hostport()}'`);
shell.assertContainsOutput(`setName: '${replSetId}'`);
});
dbname = `test-${Date.now()}-${(Math.random() * 100000) | 0}`;
await shell.executeLine(`use ${dbname}`);
await shell.executeLine('db.testcollection.insertOne({})');
shell.writeInputLine('exit');
});
after(async() => {
const shell = TestShell.start({ args: [await rs0.connectionString()] });
await shell.executeLine(`db.getSiblingDB("${dbname}").dropDatabase()`);
shell.writeInputLine('exit');
});

context('connecting to secondary members directly', () => {
Expand Down Expand Up @@ -103,6 +114,14 @@ describe('e2e direct connection', () => {
expect(await shell.executeLine('show collections')).to.include('system.version');
expect(await shell.executeLine('show dbs')).to.include('admin');
});
it('autocompletes collection names', async() => {
const shell = TestShell.start({ args: [`${await rs1.connectionString()}/${dbname}`], forceTerminal: true });
await shell.waitForPrompt();
shell.writeInput('db.testc\u0009\u0009');
await eventually(() => {
shell.assertContainsOutput('db.testcollection');
});
});
});

context('connecting to primary', () => {
Expand Down Expand Up @@ -139,6 +158,14 @@ describe('e2e direct connection', () => {
expect(await shell.executeLine('show collections')).to.include('system.version');
expect(await shell.executeLine('show dbs')).to.include('admin');
});
it('autocompletes collection names', async() => {
const shell = TestShell.start({ args: [`${await rs1.connectionString()}/${dbname}`], forceTerminal: true });
await shell.waitForPrompt();
shell.writeInput('db.testc\u0009\u0009');
await eventually(() => {
shell.assertContainsOutput('db.testcollection');
});
});
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/shell-api/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default class Database extends ShellApiClass {
async _getCollectionNamesForCompletion(): Promise<string[]> {
return await Promise.race([
(async() => {
return await this._getCollectionNames();
return await this._getCollectionNames({ readPreference: 'primaryPreferred' });
})(),
(async() => {
// 200ms should be a good compromise between giving the server a chance
Expand Down
5 changes: 4 additions & 1 deletion packages/shell-api/src/shell-internal-state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ describe('ShellInternalState', () => {
serviceProvider.listCollections
.resolves([ { name: 'coll1' }, { name: 'coll2' } ]);
expect(run('db = db.getSiblingDB("moo"); db.getName()')).to.equal('moo');
expect(serviceProvider.listCollections.calledWith('moo', {}, { nameOnly: true })).to.equal(true);
expect(serviceProvider.listCollections.calledWith('moo', {}, {
readPreference: 'primaryPreferred',
nameOnly: true
})).to.equal(true);
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/shell-api/src/shell-internal-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default class ShellInternalState {
this.context.sh = new Shard(this.currentDb);
this.fetchConnectionInfo().catch(err => this.messageBus.emit('mongosh:error', err));
// Pre-fetch for autocompletion.
this.currentDb._getCollectionNames().catch(err => this.messageBus.emit('mongosh:error', err));
this.currentDb._getCollectionNamesForCompletion().catch(err => this.messageBus.emit('mongosh:error', err));
return newDb;
}

Expand Down