Skip to content

Commit 9b18859

Browse files
committed
fix(NODE-7073): dont add duplicate metadata
1 parent 3469f86 commit 9b18859

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/mongo_client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,11 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
492492
* @param driverInfo - Information about the application or library.
493493
*/
494494
appendMetadata(driverInfo: DriverInfo) {
495+
for (const info of this.options.additionalDriverInfo) {
496+
if (info.name === driverInfo.name) {
497+
return;
498+
}
499+
}
495500
this.options.additionalDriverInfo.push(driverInfo);
496501
this.options.metadata = makeClientMetadata(this.options);
497502
this.options.extendedMetadata = addContainerMetadata(this.options.metadata)

test/integration/mongodb-handshake/mongodb-handshake.prose.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,13 @@ describe('Client Metadata Update Prose Tests', function () {
355355
// (Note os is the only one getting set in these tests)
356356
expect(updatedClientMetadata.os).to.deep.equal(initialClientMetadata.os);
357357
});
358+
359+
it('does not append duplicate metadata for the same name', async function () {
360+
client.appendMetadata({ name, version, platform });
361+
client.appendMetadata({ name, version, platform });
362+
await client.db('test').command({ ping: 1 });
363+
expect(updatedClientMetadata.driver.name).to.not.contain('|framework|framework');
364+
});
358365
});
359366
}
360367
});

0 commit comments

Comments
 (0)