diff --git a/README.md b/README.md index ac735138ab..fea44bb1c0 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ variable. For detailed instructions for each of our supported platforms, please --eval [arg] Evaluate javascript --json[=canonical|relaxed] Print result of --eval as Extended JSON, including errors --retryWrites[=true|false] Automatically retry write operations upon transient network errors (Default: true) + --skipStartupWarnings Do not display server startup warnings Authentication Options: diff --git a/packages/arg-parser/src/cli-options.ts b/packages/arg-parser/src/cli-options.ts index 932a91cf39..8238cb504e 100644 --- a/packages/arg-parser/src/cli-options.ts +++ b/packages/arg-parser/src/cli-options.ts @@ -38,6 +38,7 @@ export interface CliOptions { quiet?: boolean; retryWrites?: boolean; shell?: boolean; + skipStartupWarnings?: boolean; tls?: boolean; tlsAllowInvalidCertificates?: boolean; tlsAllowInvalidHostnames?: boolean; diff --git a/packages/cli-repl/src/arg-parser.ts b/packages/cli-repl/src/arg-parser.ts index 6d6c9840f3..932fae1d46 100644 --- a/packages/cli-repl/src/arg-parser.ts +++ b/packages/cli-repl/src/arg-parser.ts @@ -71,6 +71,7 @@ const OPTIONS = { 'retryWrites', 'shell', 'smokeTests', + 'skipStartupWarnings', 'ssl', 'sslAllowInvalidCertificates', 'sslAllowInvalidHostnames', diff --git a/packages/cli-repl/src/mongosh-repl.spec.ts b/packages/cli-repl/src/mongosh-repl.spec.ts index 8e13337ec6..aa530e0f28 100644 --- a/packages/cli-repl/src/mongosh-repl.spec.ts +++ b/packages/cli-repl/src/mongosh-repl.spec.ts @@ -1345,6 +1345,25 @@ describe('MongoshNodeRepl', function () { 'The server generated these startup warnings when booting' ); }); + + it('startup warnings are absent when skipStartupWarnings flag is present', async function () { + mongoshRepl.shellCliOptions.skipStartupWarnings = true; + // Make sure the startupWarnings resolves with errors + sp.runCommandWithCheck + .withArgs( + ADMIN_DB, + { + getLog: 'startupWarnings', + }, + {} + ) + .resolves({ ok: 1, log: logLines }); + + await mongoshRepl.initialize(serviceProvider); + expect(output).to.not.contain( + 'The server generated these startup warnings when booting' + ); + }); }); } }); diff --git a/packages/cli-repl/src/mongosh-repl.ts b/packages/cli-repl/src/mongosh-repl.ts index 63427661ac..93f197197e 100644 --- a/packages/cli-repl/src/mongosh-repl.ts +++ b/packages/cli-repl/src/mongosh-repl.ts @@ -57,6 +57,7 @@ declare const __non_webpack_require__: any; */ export type MongoshCliOptions = ShellCliOptions & { quiet?: boolean; + skipStartupWarnings?: boolean; /** * Whether to instantiate a Node.js REPL instance, including support * for async error tracking, or not. @@ -375,10 +376,12 @@ class MongoshNodeRepl implements EvaluationListener { const { shellApi } = instanceState; // Assuming `instanceState.fetchConnectionInfo()` was already called above const connectionInfo = instanceState.cachedConnectionInfo(); - // Skipping startup warnings (see https://jira.mongodb.org/browse/MONGOSH-1776) - const bannerCommands = connectionInfo?.extraInfo?.is_local_atlas - ? ['automationNotices', 'nonGenuineMongoDBCheck'] - : ['startupWarnings', 'automationNotices', 'nonGenuineMongoDBCheck']; + // Skipping startup warnings (see https://jira.mongodb.org/browse/MONGOSH-1776 and https://jira.mongodb.org/browse/MONGOSH-2371) + const bannerCommands = + connectionInfo?.extraInfo?.is_local_atlas || + this.shellCliOptions.skipStartupWarnings + ? ['automationNotices', 'nonGenuineMongoDBCheck'] + : ['startupWarnings', 'automationNotices', 'nonGenuineMongoDBCheck']; const banners = await Promise.all( bannerCommands.map( async (command) => await shellApi._untrackedShow(command)