Files
mongo/jstests/core/shell/shell_connection_strings.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

37 lines
1.4 KiB
JavaScript

// Test mongo shell connect strings.
//
// @tags: [
// # The test runs commands that are not allowed with security token: eval.
// not_allowed_with_signed_security_token,
// uses_multiple_connections,
// docker_incompatible,
// ]
const mongod = new MongoURI(db.getMongo().host).servers[0];
const host = mongod.host;
const port = mongod.port;
function testConnect(ok, ...args) {
const exitCode = runMongoProgram("mongo", "--eval", ";", ...args);
if (ok) {
assert.eq(exitCode, 0, "failed to connect with `" + args.join(" ") + "`");
} else {
assert.neq(exitCode, 0, "unexpectedly succeeded connecting with `" + args.join(" ") + "`");
}
}
testConnect(true, `${host}:${port}`);
testConnect(true, `${host}:${port}/test`);
testConnect(true, `${host}:${port}/admin`);
testConnect(true, host, "--port", port);
testConnect(true, "--host", host, "--port", port, "test");
testConnect(true, "--host", host, "--port", port, "admin");
testConnect(true, `mongodb://${host}:${port}/test`);
testConnect(true, `mongodb://${host}:${port}/test?connectTimeoutMS=10000`);
// if a full URI is provided, you cannot also specify host or port
testConnect(false, `${host}/test`, "--port", port);
testConnect(false, `mongodb://${host}:${port}/test`, "--port", port);
testConnect(false, `mongodb://${host}:${port}/test`, "--host", host);
testConnect(false, `mongodb://${host}:${port}/test`, "--host", host, "--port", port);