Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shell-api): introduces public Mongo.getURI #1391

Merged
merged 2 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 11 additions & 2 deletions packages/shell-api/src/mongo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,24 @@ describe('Mongo', () => {
});
});
describe('Metadata', () => {
const MONGO_URI = 'localhost:37017';
const MONGO_CONNECTION_STRING = 'mongodb://localhost:37017/?directConnection=true&serverSelectionTimeoutMS=2000';
const mongo = new Mongo({} as any, MONGO_URI);

describe('toShellResult', () => {
const mongo = new Mongo({} as any, 'localhost:37017');
it('value', async() => {
expect((await toShellResult(mongo)).printable).to.equal('mongodb://localhost:37017/?directConnection=true&serverSelectionTimeoutMS=2000');
expect((await toShellResult(mongo)).printable).to.equal(MONGO_CONNECTION_STRING);
});
it('type', async() => {
expect((await toShellResult(mongo)).type).to.equal('Mongo');
});
});

describe('getURI', () => {
it('returns the connection string of active connection', () => {
expect(mongo.getURI()).to.equal(MONGO_CONNECTION_STRING);
});
});
});
describe('commands', () => {
const driverSession = { driverSession: 1 };
Expand Down
4 changes: 4 additions & 0 deletions packages/shell-api/src/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ export default class Mongo extends ShellApiClass {
return this._getDb(db).getCollection(coll);
}

getURI(): string {
return this._uri;
}

use(db: string): string {
assertArgsDefinedType([db], ['string'], 'Mongo.use');
this._instanceState.messageBus.emit('mongosh:use', { db });
Expand Down