Skip to content

Commit cff451e

Browse files
authored
feat: Add support for more MongoDB driver options (#9911)
1 parent 4124069 commit cff451e

File tree

5 files changed

+368
-17
lines changed

5 files changed

+368
-17
lines changed

spec/ParseConfigKey.spec.js

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,70 @@ describe('Config Keys', () => {
7373
filesAdapter: null,
7474
databaseAdapter: null,
7575
databaseOptions: {
76-
retryWrites: true,
77-
maxTimeMS: 1000,
78-
maxStalenessSeconds: 10,
76+
appName: 'MyParseApp',
77+
78+
// Cannot be tested as it requires authentication setup
79+
// authMechanism: 'SCRAM-SHA-256',
80+
// authMechanismProperties: { SERVICE_NAME: 'mongodb' },
81+
82+
authSource: 'admin',
83+
autoSelectFamily: true,
84+
autoSelectFamilyAttemptTimeout: 3000,
85+
compressors: ['zlib'],
86+
connectTimeoutMS: 5000,
87+
directConnection: false,
88+
disableIndexFieldValidation: true,
89+
forceServerObjectId: false,
90+
heartbeatFrequencyMS: 10000,
91+
localThresholdMS: 15,
92+
maxConnecting: 2,
93+
maxIdleTimeMS: 60000,
7994
maxPoolSize: 10,
95+
maxStalenessSeconds: 90,
96+
maxTimeMS: 1000,
8097
minPoolSize: 5,
98+
99+
// Cannot be tested as it requires a proxy setup
100+
// proxyHost: 'proxy.example.com',
101+
// proxyPassword: 'proxypass',
102+
// proxyPort: 1080,
103+
// proxyUsername: 'proxyuser',
104+
105+
readConcernLevel: 'majority',
106+
readPreference: 'secondaryPreferred',
107+
readPreferenceTags: [{ dc: 'east' }],
108+
109+
// Cannot be tested as it requires a replica set setup
110+
// replicaSet: 'myReplicaSet',
111+
112+
retryReads: true,
113+
retryWrites: true,
114+
serverMonitoringMode: 'auto',
81115
serverSelectionTimeoutMS: 5000,
82-
maxIdleTimeMS: 60000,
83-
heartbeatFrequencyMS: 10000,
84-
connectTimeoutMS: 5000,
85116
socketTimeoutMS: 5000,
86-
autoSelectFamily: true,
87-
autoSelectFamilyAttemptTimeout: 3000,
88-
disableIndexFieldValidation: true
117+
118+
// Cannot be tested as it requires a replica cluster setup
119+
// srvMaxHosts: 0,
120+
// srvServiceName: 'mongodb',
121+
122+
ssl: false,
123+
tls: false,
124+
tlsAllowInvalidCertificates: false,
125+
tlsAllowInvalidHostnames: false,
126+
tlsCAFile: __dirname + '/support/cert/cert.pem',
127+
tlsCertificateKeyFile: __dirname + '/support/cert/cert.pem',
128+
tlsCertificateKeyFilePassword: 'password',
129+
waitQueueTimeoutMS: 5000,
130+
zlibCompressionLevel: 6,
131+
},
132+
})).toBeResolved();
133+
await expectAsync(reconfigureServer({
134+
databaseURI: 'mongodb://localhost:27017/parse',
135+
filesAdapter: null,
136+
databaseAdapter: null,
137+
databaseOptions: {
138+
// The following option needs to be tested separately due to driver config rules
139+
tlsInsecure: false,
89140
},
90141
})).toBeResolved();
91142
expect(loggerErrorSpy.calls.all().reduce((s, call) => s += call.args[0], '')).not.toMatch(invalidKeyErrorMessage);

src/Options/Definitions.js

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,27 @@ module.exports.FileUploadOptions = {
10841084
},
10851085
};
10861086
module.exports.DatabaseOptions = {
1087+
appName: {
1088+
env: 'PARSE_SERVER_DATABASE_APP_NAME',
1089+
help:
1090+
'The MongoDB driver option to specify the name of the application that created this MongoClient instance.',
1091+
},
1092+
authMechanism: {
1093+
env: 'PARSE_SERVER_DATABASE_AUTH_MECHANISM',
1094+
help:
1095+
'The MongoDB driver option to specify the authentication mechanism that MongoDB will use to authenticate the connection.',
1096+
},
1097+
authMechanismProperties: {
1098+
env: 'PARSE_SERVER_DATABASE_AUTH_MECHANISM_PROPERTIES',
1099+
help:
1100+
'The MongoDB driver option to specify properties for the specified authMechanism as a comma-separated list of colon-separated key-value pairs.',
1101+
action: parsers.objectParser,
1102+
},
1103+
authSource: {
1104+
env: 'PARSE_SERVER_DATABASE_AUTH_SOURCE',
1105+
help:
1106+
"The MongoDB driver option to specify the database name associated with the user's credentials.",
1107+
},
10871108
autoSelectFamily: {
10881109
env: 'PARSE_SERVER_DATABASE_AUTO_SELECT_FAMILY',
10891110
help:
@@ -1096,6 +1117,11 @@ module.exports.DatabaseOptions = {
10961117
'The MongoDB driver option to specify the amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the autoSelectFamily option. If set to a positive integer less than 10, the value 10 is used instead.',
10971118
action: parsers.numberParser('autoSelectFamilyAttemptTimeout'),
10981119
},
1120+
compressors: {
1121+
env: 'PARSE_SERVER_DATABASE_COMPRESSORS',
1122+
help:
1123+
'The MongoDB driver option to specify an array or comma-delimited string of compressors to enable network compression for communication between this client and a mongod/mongos instance.',
1124+
},
10991125
connectTimeoutMS: {
11001126
env: 'PARSE_SERVER_DATABASE_CONNECT_TIMEOUT_MS',
11011127
help:
@@ -1151,6 +1177,12 @@ module.exports.DatabaseOptions = {
11511177
action: parsers.booleanParser,
11521178
default: true,
11531179
},
1180+
directConnection: {
1181+
env: 'PARSE_SERVER_DATABASE_DIRECT_CONNECTION',
1182+
help:
1183+
'The MongoDB driver option to force a Single topology type with a connection string containing one host.',
1184+
action: parsers.booleanParser,
1185+
},
11541186
disableIndexFieldValidation: {
11551187
env: 'PARSE_SERVER_DATABASE_DISABLE_INDEX_FIELD_VALIDATION',
11561188
help:
@@ -1164,12 +1196,35 @@ module.exports.DatabaseOptions = {
11641196
action: parsers.booleanParser,
11651197
default: false,
11661198
},
1199+
forceServerObjectId: {
1200+
env: 'PARSE_SERVER_DATABASE_FORCE_SERVER_OBJECT_ID',
1201+
help: 'The MongoDB driver option to force server to assign _id values instead of driver.',
1202+
action: parsers.booleanParser,
1203+
},
11671204
heartbeatFrequencyMS: {
11681205
env: 'PARSE_SERVER_DATABASE_HEARTBEAT_FREQUENCY_MS',
11691206
help:
11701207
'The MongoDB driver option to specify the frequency in milliseconds at which the driver checks the state of the MongoDB deployment.',
11711208
action: parsers.numberParser('heartbeatFrequencyMS'),
11721209
},
1210+
loadBalanced: {
1211+
env: 'PARSE_SERVER_DATABASE_LOAD_BALANCED',
1212+
help:
1213+
'The MongoDB driver option to instruct the driver it is connecting to a load balancer fronting a mongos like service.',
1214+
action: parsers.booleanParser,
1215+
},
1216+
localThresholdMS: {
1217+
env: 'PARSE_SERVER_DATABASE_LOCAL_THRESHOLD_MS',
1218+
help:
1219+
'The MongoDB driver option to specify the size (in milliseconds) of the latency window for selecting among multiple suitable MongoDB instances.',
1220+
action: parsers.numberParser('localThresholdMS'),
1221+
},
1222+
maxConnecting: {
1223+
env: 'PARSE_SERVER_DATABASE_MAX_CONNECTING',
1224+
help:
1225+
'The MongoDB driver option to specify the maximum number of connections that may be in the process of being established concurrently by the connection pool.',
1226+
action: parsers.numberParser('maxConnecting'),
1227+
},
11731228
maxIdleTimeMS: {
11741229
env: 'PARSE_SERVER_DATABASE_MAX_IDLE_TIME_MS',
11751230
help:
@@ -1200,6 +1255,51 @@ module.exports.DatabaseOptions = {
12001255
'The MongoDB driver option to set the minimum number of opened, cached, ready-to-use database connections maintained by the driver.',
12011256
action: parsers.numberParser('minPoolSize'),
12021257
},
1258+
proxyHost: {
1259+
env: 'PARSE_SERVER_DATABASE_PROXY_HOST',
1260+
help:
1261+
'The MongoDB driver option to configure a Socks5 proxy host used for creating TCP connections.',
1262+
},
1263+
proxyPassword: {
1264+
env: 'PARSE_SERVER_DATABASE_PROXY_PASSWORD',
1265+
help:
1266+
'The MongoDB driver option to configure a Socks5 proxy password when the proxy requires username/password authentication.',
1267+
},
1268+
proxyPort: {
1269+
env: 'PARSE_SERVER_DATABASE_PROXY_PORT',
1270+
help:
1271+
'The MongoDB driver option to configure a Socks5 proxy port used for creating TCP connections.',
1272+
action: parsers.numberParser('proxyPort'),
1273+
},
1274+
proxyUsername: {
1275+
env: 'PARSE_SERVER_DATABASE_PROXY_USERNAME',
1276+
help:
1277+
'The MongoDB driver option to configure a Socks5 proxy username when the proxy requires username/password authentication.',
1278+
},
1279+
readConcernLevel: {
1280+
env: 'PARSE_SERVER_DATABASE_READ_CONCERN_LEVEL',
1281+
help: 'The MongoDB driver option to specify the level of isolation.',
1282+
},
1283+
readPreference: {
1284+
env: 'PARSE_SERVER_DATABASE_READ_PREFERENCE',
1285+
help: 'The MongoDB driver option to specify the read preferences for this connection.',
1286+
},
1287+
readPreferenceTags: {
1288+
env: 'PARSE_SERVER_DATABASE_READ_PREFERENCE_TAGS',
1289+
help:
1290+
'The MongoDB driver option to specify the tags document as a comma-separated list of colon-separated key-value pairs.',
1291+
action: parsers.arrayParser,
1292+
},
1293+
replicaSet: {
1294+
env: 'PARSE_SERVER_DATABASE_REPLICA_SET',
1295+
help:
1296+
'The MongoDB driver option to specify the name of the replica set, if the mongod is a member of a replica set.',
1297+
},
1298+
retryReads: {
1299+
env: 'PARSE_SERVER_DATABASE_RETRY_READS',
1300+
help: 'The MongoDB driver option to enable retryable reads.',
1301+
action: parsers.booleanParser,
1302+
},
12031303
retryWrites: {
12041304
env: 'PARSE_SERVER_DATABASE_RETRY_WRITES',
12051305
help: 'The MongoDB driver option to set whether to retry failed writes.',
@@ -1211,6 +1311,11 @@ module.exports.DatabaseOptions = {
12111311
'The duration in seconds after which the schema cache expires and will be refetched from the database. Use this option if using multiple Parse Servers instances connected to the same database. A low duration will cause the schema cache to be updated too often, causing unnecessary database reads. A high duration will cause the schema to be updated too rarely, increasing the time required until schema changes propagate to all server instances. This feature can be used as an alternative or in conjunction with the option `enableSchemaHooks`. Default is infinite which means the schema cache never expires.',
12121312
action: parsers.numberParser('schemaCacheTtl'),
12131313
},
1314+
serverMonitoringMode: {
1315+
env: 'PARSE_SERVER_DATABASE_SERVER_MONITORING_MODE',
1316+
help:
1317+
'The MongoDB driver option to instruct the driver monitors to use a specific monitoring mode.',
1318+
},
12141319
serverSelectionTimeoutMS: {
12151320
env: 'PARSE_SERVER_DATABASE_SERVER_SELECTION_TIMEOUT_MS',
12161321
help:
@@ -1223,6 +1328,70 @@ module.exports.DatabaseOptions = {
12231328
'The MongoDB driver option to specify the amount of time, in milliseconds, spent attempting to send or receive on a socket before timing out. Specifying 0 means no timeout.',
12241329
action: parsers.numberParser('socketTimeoutMS'),
12251330
},
1331+
srvMaxHosts: {
1332+
env: 'PARSE_SERVER_DATABASE_SRV_MAX_HOSTS',
1333+
help:
1334+
'The MongoDB driver option to specify the maximum number of hosts to connect to when using an srv connection string, a setting of 0 means unlimited hosts.',
1335+
action: parsers.numberParser('srvMaxHosts'),
1336+
},
1337+
srvServiceName: {
1338+
env: 'PARSE_SERVER_DATABASE_SRV_SERVICE_NAME',
1339+
help: 'The MongoDB driver option to modify the srv URI service name.',
1340+
},
1341+
ssl: {
1342+
env: 'PARSE_SERVER_DATABASE_SSL',
1343+
help:
1344+
'The MongoDB driver option to enable or disable TLS/SSL for the connection (equivalent to tls option).',
1345+
action: parsers.booleanParser,
1346+
},
1347+
tls: {
1348+
env: 'PARSE_SERVER_DATABASE_TLS',
1349+
help: 'The MongoDB driver option to enable or disable TLS/SSL for the connection.',
1350+
action: parsers.booleanParser,
1351+
},
1352+
tlsAllowInvalidCertificates: {
1353+
env: 'PARSE_SERVER_DATABASE_TLS_ALLOW_INVALID_CERTIFICATES',
1354+
help:
1355+
'The MongoDB driver option to bypass validation of the certificates presented by the mongod/mongos instance.',
1356+
action: parsers.booleanParser,
1357+
},
1358+
tlsAllowInvalidHostnames: {
1359+
env: 'PARSE_SERVER_DATABASE_TLS_ALLOW_INVALID_HOSTNAMES',
1360+
help:
1361+
'The MongoDB driver option to disable hostname validation of the certificate presented by the mongod/mongos instance.',
1362+
action: parsers.booleanParser,
1363+
},
1364+
tlsCAFile: {
1365+
env: 'PARSE_SERVER_DATABASE_TLS_CAFILE',
1366+
help:
1367+
'The MongoDB driver option to specify the location of a local .pem file that contains the root certificate chain from the Certificate Authority.',
1368+
},
1369+
tlsCertificateKeyFile: {
1370+
env: 'PARSE_SERVER_DATABASE_TLS_CERTIFICATE_KEY_FILE',
1371+
help:
1372+
"The MongoDB driver option to specify the location of a local .pem file that contains the client's TLS/SSL certificate and key.",
1373+
},
1374+
tlsCertificateKeyFilePassword: {
1375+
env: 'PARSE_SERVER_DATABASE_TLS_CERTIFICATE_KEY_FILE_PASSWORD',
1376+
help: 'The MongoDB driver option to specify the password to decrypt the tlsCertificateKeyFile.',
1377+
},
1378+
tlsInsecure: {
1379+
env: 'PARSE_SERVER_DATABASE_TLS_INSECURE',
1380+
help: 'The MongoDB driver option to disable various certificate validations.',
1381+
action: parsers.booleanParser,
1382+
},
1383+
waitQueueTimeoutMS: {
1384+
env: 'PARSE_SERVER_DATABASE_WAIT_QUEUE_TIMEOUT_MS',
1385+
help:
1386+
'The MongoDB driver option to specify the maximum time in milliseconds that a thread can wait for a connection to become available.',
1387+
action: parsers.numberParser('waitQueueTimeoutMS'),
1388+
},
1389+
zlibCompressionLevel: {
1390+
env: 'PARSE_SERVER_DATABASE_ZLIB_COMPRESSION_LEVEL',
1391+
help:
1392+
'The MongoDB driver option to specify the compression level if using zlib for network compression (0-9).',
1393+
action: parsers.numberParser('zlibCompressionLevel'),
1394+
},
12261395
};
12271396
module.exports.AuthAdapter = {
12281397
enabled: {

0 commit comments

Comments
 (0)