@@ -34,7 +34,7 @@ var validOptionNames = ['poolSize', 'ssl', 'sslValidate', 'sslCA', 'sslCert',
34
34
'serializeFunctions' , 'ignoreUndefined' , 'raw' , 'promoteLongs' , 'bufferMaxEntries' ,
35
35
'readPreference' , 'pkFactory' , 'promiseLibrary' , 'readConcern' , 'maxStalenessSeconds' ,
36
36
'loggerLevel' , 'logger' , 'promoteValues' , 'promoteBuffers' , 'promoteLongs' ,
37
- 'domainsEnabled' , 'keepAliveInitialDelay' , 'checkServerIdentity' ] ;
37
+ 'domainsEnabled' , 'keepAliveInitialDelay' , 'checkServerIdentity' , 'validateOptions' ] ;
38
38
var ignoreOptionNames = [ 'native_parser' ] ;
39
39
var legacyOptionNames = [ 'server' , 'replset' , 'replSet' , 'mongos' , 'db' ] ;
40
40
@@ -46,11 +46,13 @@ function validOptions(options) {
46
46
continue ;
47
47
}
48
48
49
- if ( _validOptions . indexOf ( name ) == - 1 ) {
49
+ if ( _validOptions . indexOf ( name ) == - 1 && options . validateOptions ) {
50
50
return new MongoError ( f ( 'option %s is not supported' , name ) ) ;
51
+ } else if ( _validOptions . indexOf ( name ) == - 1 ) {
52
+ console . warn ( f ( 'the options [%s] is not supported' , name ) ) ;
51
53
}
52
54
53
- if ( legacyOptionNames . indexOf ( name ) = = - 1 ) {
55
+ if ( legacyOptionNames . indexOf ( name ) ! = - 1 ) {
54
56
console . warn ( f ( 'the server/replset/mongos options are deprecated, '
55
57
+ 'all their options are supported at the top level of the options object [%s]' , validOptionNames ) ) ;
56
58
}
@@ -121,6 +123,7 @@ function MongoClient() {
121
123
* @param {number } [options.maxStalenessSeconds=undefined] The max staleness to secondary reads (values under 10 seconds cannot be guaranteed);
122
124
* @param {string } [options.loggerLevel=undefined] The logging level (error/warn/info/debug)
123
125
* @param {object } [options.logger=undefined] Custom logger object
126
+ * @param {object } [options.validateOptions=false] Validate MongoClient passed in options for correctness.
124
127
* @param {MongoClient~connectCallback } [callback] The command result callback
125
128
* @return {Promise } returns Promise if no callback passed
126
129
*/
@@ -181,6 +184,7 @@ var define = MongoClient.define = new Define('MongoClient', MongoClient, false);
181
184
* @param {number } [options.maxStalenessSeconds=undefined] The max staleness to secondary reads (values under 10 seconds cannot be guaranteed);
182
185
* @param {string } [options.loggerLevel=undefined] The logging level (error/warn/info/debug)
183
186
* @param {object } [options.logger=undefined] Custom logger object
187
+ * @param {object } [options.validateOptions=false] Validate MongoClient passed in options for correctness.
184
188
* @param {MongoClient~connectCallback } [callback] The command result callback
185
189
* @return {Promise } returns Promise if no callback passed
186
190
*/
0 commit comments