Skip to content

Commit 3ab3266

Browse files
authored
feat(cli-repl): include API version in greeting message (#881)
This is mostly so that when `--apiStrict` is used, we’ll show the API version instead of just `Using MongoDB: undefined` (which fits, because in that case the API version effectively fills the role the server version currently has).
1 parent 37d527e commit 3ab3266

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/cli-repl/src/mongosh-repl.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ class MongoshNodeRepl implements EvaluationListener {
129129
internalState.setEvaluationListener(this);
130130
await internalState.fetchConnectionInfo();
131131

132-
const mongodVersion = internalState.connectionInfo.buildInfo?.version;
132+
let mongodVersion = internalState.connectionInfo.buildInfo?.version;
133+
const apiVersion = serviceProvider.getRawClient()?.serverApi?.version;
134+
if (apiVersion) {
135+
mongodVersion = (mongodVersion ? mongodVersion + ' ' : '') + `(API Version ${apiVersion})`;
136+
}
133137
await this.greet(mongodVersion);
134138
await this.printStartupLog(internalState);
135139

packages/cli-repl/test/e2e.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,22 @@ describe('e2e', function() {
906906
`${await testServer.connectionString()}/${dbName}`, '--apiVersion', '1'
907907
] });
908908
await shell.waitForPrompt();
909+
shell.assertContainsOutput('(API Version 1)');
910+
expect(await shell.executeLine('db.coll.find().toArray()'))
911+
.to.include('[]');
912+
shell.assertNoErrors();
913+
});
914+
915+
it('can specify an API version and strict mode', async function() {
916+
// Disable this until https://jira.mongodb.org/browse/NODE-3183
917+
// is done because the server has started requiring hello instead of
918+
// isMaster.
919+
return this.skip();
920+
const shell = TestShell.start({ args: [
921+
`${await testServer.connectionString()}/${dbName}`, '--apiVersion', '1', '--apiStrict', '--apiDeprecationErrors'
922+
] });
923+
await shell.waitForPrompt();
924+
shell.assertContainsOutput('(API Version 1)');
909925
expect(await shell.executeLine('db.coll.find().toArray()'))
910926
.to.include('[]');
911927
shell.assertNoErrors();

0 commit comments

Comments
 (0)