File tree 3 files changed +30
-2
lines changed
3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ import {
11
11
resolveOptions ,
12
12
ClientMetadata ,
13
13
ns ,
14
- HostAddress
14
+ HostAddress ,
15
+ NODE_DRIVER_VERSION
15
16
} from './utils' ;
16
17
import { deprecate } from 'util' ;
17
18
import { connect } from './operations/connect' ;
@@ -579,6 +580,11 @@ export class MongoClient extends EventEmitter {
579
580
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
580
581
if ( typeof callback === 'function' ) callback ( undefined , true ) ;
581
582
} , 'Multiple authentication is prohibited on a connected client, please only authenticate once per MongoClient' ) ;
583
+
584
+ /** Provides the version of the 'mongodb' package. */
585
+ static get version ( ) : string {
586
+ return NODE_DRIVER_VERSION ;
587
+ }
582
588
}
583
589
584
590
/**
Original file line number Diff line number Diff line change @@ -889,8 +889,9 @@ export interface ClientMetadataOptions {
889
889
appName ?: string ;
890
890
}
891
891
892
+ /** @internal */
892
893
// eslint-disable-next-line @typescript-eslint/no-var-requires
893
- const NODE_DRIVER_VERSION = require ( '../package.json' ) . version ;
894
+ export const NODE_DRIVER_VERSION = require ( '../package.json' ) . version ;
894
895
895
896
export function makeClientMetadata ( options ?: ClientMetadataOptions ) : ClientMetadata {
896
897
options = options ?? { } ;
Original file line number Diff line number Diff line change @@ -170,6 +170,27 @@ describe('MongoClient', function () {
170
170
}
171
171
} ) ;
172
172
173
+ it ( 'Should provide the same package version in metadata and on the MongoClient class' , {
174
+ metadata : {
175
+ requires : {
176
+ topology : [ 'single' , 'replicaset' , 'sharded' ]
177
+ }
178
+ } ,
179
+
180
+ test : function ( done ) {
181
+ var configuration = this . configuration ;
182
+ var url = configuration . url ( ) ;
183
+
184
+ const client = configuration . newClient ( url , { appname : 'hello world' } ) ;
185
+ client . connect ( err => {
186
+ expect ( err ) . to . not . exist ;
187
+ test . equal ( client . topology . clientMetadata . driver . version , client . constructor . version ) ;
188
+
189
+ client . close ( done ) ;
190
+ } ) ;
191
+ }
192
+ } ) ;
193
+
173
194
it ( 'Should correctly pass through socketTimeoutMS and connectTimeoutMS' , {
174
195
metadata : {
175
196
requires : {
You can’t perform that action at this time.
0 commit comments