Skip to content

Commit 8c2da63

Browse files
committed
chore: generate the connection string properly on first connection
This is necessary when connecting for the first time.
1 parent c79a479 commit 8c2da63

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 = {
@@ -286,21 +286,9 @@ export function setupUserConfig({
286286
userConfig.loggers = commaSeparatedToArray(userConfig.loggers);
287287

288288
if (userConfig.connectionString && userConfig.connectionSpecifier) {
289-
delete userConfig.connectionString;
289+
const connectionInfo = generateConnectionInfoFromCliArgs(userConfig);
290+
userConfig.connectionString = connectionInfo.connectionString;
290291
}
291292

292293
return userConfig;
293294
}
294-
295-
/**
296-
readConcern: {
297-
level: settings.readConcern,
298-
},
299-
readPreference: settings.readPreference,
300-
writeConcern: {
301-
w: settings.writeConcern,
302-
},
303-
timeoutMS: settings.timeoutMS,
304-
proxy: { useEnvironmentVariableProxies: true },
305-
applyProxyToOIDC: true,
306-
**/

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)