Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/data-service/src/connect-mongo-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ describe('connectMongoClient', function () {
});
});

it('should not override a user-specified directConnection option', async function () {
const [client, tunnel, { url, options }] = await connectMongoClient(
{
connectionString: 'mongodb://localhost:27018/?directConnection=false',
},
setupListeners,
tunnelLocalPort
);

toBeClosed.push(client, tunnel);

assert.strictEqual(
url,
'mongodb://localhost:27018/?directConnection=false'
);

assert.deepStrictEqual(options, {
monitorCommands: true,
});
});

it('should at least try to run a ping command to verify connectivity', async function () {
try {
await connectMongoClient(
Expand Down
3 changes: 2 additions & 1 deletion packages/data-service/src/connect-mongo-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ function connectionOptionsToMongoClientParams(
const isLoadBalanced = url.searchParams.get('loadBalanced') === 'true';
const isReplicaSet =
url.isSRV || url.hosts.length > 1 || url.searchParams.has('replicaSet');
const hasDirectConnection = url.searchParams.has('directConnection');

if (!isReplicaSet && !isLoadBalanced) {
if (!isReplicaSet && !isLoadBalanced && !hasDirectConnection) {
url.searchParams.set('directConnection', 'true');
}

Expand Down