diff --git a/src/mongo_client.ts b/src/mongo_client.ts index 1ff310822db..3f883429f13 100644 --- a/src/mongo_client.ts +++ b/src/mongo_client.ts @@ -492,6 +492,11 @@ export class MongoClient extends TypedEventEmitter implements * @param driverInfo - Information about the application or library. */ appendMetadata(driverInfo: DriverInfo) { + for (const info of this.options.additionalDriverInfo) { + if (info.name === driverInfo.name && info.version === driverInfo.version) { + return; + } + } this.options.additionalDriverInfo.push(driverInfo); this.options.metadata = makeClientMetadata(this.options); this.options.extendedMetadata = addContainerMetadata(this.options.metadata) diff --git a/test/integration/mongodb-handshake/mongodb-handshake.prose.test.ts b/test/integration/mongodb-handshake/mongodb-handshake.prose.test.ts index da5b98227be..8cf9115ddcc 100644 --- a/test/integration/mongodb-handshake/mongodb-handshake.prose.test.ts +++ b/test/integration/mongodb-handshake/mongodb-handshake.prose.test.ts @@ -355,6 +355,19 @@ describe('Client Metadata Update Prose Tests', function () { // (Note os is the only one getting set in these tests) expect(updatedClientMetadata.os).to.deep.equal(initialClientMetadata.os); }); + + it('does not append duplicate metadata for the same name and version', async function () { + client.appendMetadata({ name, version, platform }); + client.appendMetadata({ name, version, platform }); + await client.db('test').command({ ping: 1 }); + expect(updatedClientMetadata.driver.name).to.not.contain('|framework|framework'); + }); + + it('appends metadata when the version differs', async function () { + client.appendMetadata({ name, version: '0.0', platform }); + await client.db('test').command({ ping: 1 }); + expect(updatedClientMetadata.driver.name).to.not.contain('0.0'); + }); }); } });