Skip to content

Commit 7b3e063

Browse files
committed
chore: generate the connection string properly on first connection
This is necessary when connecting for the first time.
1 parent 32ede21 commit 7b3e063

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

src/common/config.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import path from "path";
22
import os from "os";
33
import argv from "yargs-parser";
4-
import type { CliOptions } from "@mongosh/arg-parser";
5-
import type { ConnectionInfo } from "@mongosh/arg-parser";
4+
import type { CliOptions, ConnectionInfo } from "@mongosh/arg-parser";
5+
import { generateConnectionInfoFromCliArgs } from "@mongosh/arg-parser";
66

77
// From: https://github.com/mongodb-js/mongosh/blob/main/packages/cli-repl/src/arg-parser.ts
88
const OPTIONS = {
@@ -296,21 +296,9 @@ export function setupUserConfig({
296296
userConfig.loggers = commaSeparatedToArray(userConfig.loggers);
297297

298298
if (userConfig.connectionString && userConfig.connectionSpecifier) {
299-
delete userConfig.connectionString;
299+
const connectionInfo = generateConnectionInfoFromCliArgs(userConfig);
300+
userConfig.connectionString = connectionInfo.connectionString;
300301
}
301302

302303
return userConfig;
303304
}
304-
305-
/**
306-
readConcern: {
307-
level: settings.readConcern,
308-
},
309-
readPreference: settings.readPreference,
310-
writeConcern: {
311-
w: settings.writeConcern,
312-
},
313-
timeoutMS: settings.timeoutMS,
314-
proxy: { useEnvironmentVariableProxies: true },
315-
applyProxyToOIDC: true,
316-
**/

src/lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { Server, type ServerOptions } from "./server.js";
22
export { Telemetry } from "./telemetry/telemetry.js";
33
export { Session, type SessionOptions } from "./common/session.js";
4-
export type { UserConfig, ConnectOptions } from "./common/config.js";
4+
export type { UserConfig } from "./common/config.js";

tests/unit/common/config.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,10 @@ describe("config", () => {
404404
defaults: {},
405405
});
406406

407-
expect(actual.connectionString).toBe(undefined);
407+
// the shell specifies directConnection=true and serverSelectionTimeoutMS=2000 by default
408+
expect(actual.connectionString).toBe(
409+
"mongodb://localhost/?directConnection=true&serverSelectionTimeoutMS=2000"
410+
);
408411
expect(actual.connectionSpecifier).toBe("mongodb://localhost");
409412
});
410413
});

0 commit comments

Comments
 (0)