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'; } 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({