From fb00c46ed5435125fd40c5de756b5064e8192e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Mon, 27 Oct 2025 15:15:09 +0100 Subject: [PATCH 1/2] Add short-circuit on servers from Atlas / mongodb.net --- packages/mongodb-build-info/src/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/mongodb-build-info/src/index.ts b/packages/mongodb-build-info/src/index.ts index dfde7a08..07111a9f 100644 --- a/packages/mongodb-build-info/src/index.ts +++ b/packages/mongodb-build-info/src/index.ts @@ -158,6 +158,10 @@ export async function identifyServerName({ }: IdentifyServerNameOptions): Promise { try { const hostname = getHostnameFromUrl(connectionString); + if (hostname.match(ATLAS_REGEX)) { + return 'mongodb'; + } + if (hostname.match(COSMOS_DB_REGEX)) { return 'cosmosdb'; } From 826e6dbffed5cdc4824cfb61d6a1257d4bb6e04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Mon, 27 Oct 2025 15:22:37 +0100 Subject: [PATCH 2/2] Add test --- packages/mongodb-build-info/test/fixtures.ts | 7 +++++++ packages/mongodb-build-info/test/index.spec.ts | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/mongodb-build-info/test/fixtures.ts b/packages/mongodb-build-info/test/fixtures.ts index 006610c6..6c3efa01 100644 --- a/packages/mongodb-build-info/test/fixtures.ts +++ b/packages/mongodb-build-info/test/fixtures.ts @@ -69,6 +69,13 @@ export const CMD_LINE_OPTS = { ok: 1, }; +export const ATLAS_URIS = [ + 'mongodb+srv://x:y@cluster0.nxezgv0.mongodb.net/', + 'mongodb+srv://x:y@cluster0.nxezgv0.mongodb-qa.net/', + 'mongodb+srv://x:y@cluster0.nxezgv0.mongodb-dev.net/', + 'mongodb://x:y@atlas-stream-64ba1372b2a9f1545031f34d-gkumd.virginia-usa.a.query.mongodb.net/', +]; + export const COSMOS_DB_URI = [ 'mongodb://x:y@compass-serverless.mongo.cosmos.azure.com:19555/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=@compass-serverless@', 'mongodb://x:y@compass.mongo.cosmos.azure.com:19555/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=@compass@', diff --git a/packages/mongodb-build-info/test/index.spec.ts b/packages/mongodb-build-info/test/index.spec.ts index f206b143..22387abc 100644 --- a/packages/mongodb-build-info/test/index.spec.ts +++ b/packages/mongodb-build-info/test/index.spec.ts @@ -436,6 +436,16 @@ describe('mongodb-build-info', function () { return Promise.reject(new Error('Should not be called')); } + it('reports MongoDB (when Atlas)', async function () { + for (const connectionString of fixtures.ATLAS_URIS) { + const result = await identifyServerName({ + connectionString, + adminCommand: fail, + }); + expect(result).to.equal('mongodb'); + } + }); + it('reports CosmosDB', async function () { for (const connectionString of fixtures.COSMOS_DB_URI) { const result = await identifyServerName({