mongodb 3.3.5 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/HISTORY.md +36 -0
  2. package/lib/bulk/common.js +9 -4
  3. package/lib/bulk/ordered.js +9 -4
  4. package/lib/bulk/unordered.js +9 -4
  5. package/lib/collection.js +120 -36
  6. package/lib/core/auth/scram.js +42 -6
  7. package/lib/core/cmap/connection.js +220 -0
  8. package/lib/core/cmap/message_stream.js +181 -0
  9. package/lib/core/connection/apm.js +14 -16
  10. package/lib/core/connection/connect.js +39 -37
  11. package/lib/core/connection/connection.js +17 -1
  12. package/lib/core/connection/logger.js +9 -4
  13. package/lib/core/connection/msg.js +1 -1
  14. package/lib/core/connection/pool.js +26 -13
  15. package/lib/core/error.js +14 -2
  16. package/lib/core/sdam/monitoring.js +3 -0
  17. package/lib/core/sdam/server_selection.js +5 -4
  18. package/lib/core/sdam/srv_polling.js +1 -1
  19. package/lib/core/sdam/topology_description.js +7 -9
  20. package/lib/core/sessions.js +5 -8
  21. package/lib/core/uri_parser.js +48 -0
  22. package/lib/core/utils.js +1 -3
  23. package/lib/core/wireprotocol/command.js +12 -3
  24. package/lib/core/wireprotocol/compression.js +13 -13
  25. package/lib/db.js +3 -1
  26. package/lib/gridfs/grid_store.js +15 -8
  27. package/lib/gridfs-stream/download.js +5 -4
  28. package/lib/gridfs-stream/index.js +3 -2
  29. package/lib/gridfs-stream/upload.js +3 -3
  30. package/lib/mongo_client.js +35 -35
  31. package/lib/operations/command_v2.js +1 -3
  32. package/lib/operations/common_functions.js +1 -2
  33. package/lib/operations/connect.js +33 -3
  34. package/lib/operations/create_collection.js +1 -2
  35. package/lib/operations/db_ops.js +2 -4
  36. package/lib/operations/execute_operation.js +2 -1
  37. package/lib/operations/map_reduce.js +2 -1
  38. package/package.json +7 -6
@@ -55,26 +55,12 @@ const CloseOperation = require('./operations/close');
55
55
  */
56
56
 
57
57
  /**
58
- * Configuration options for a automatic client encryption.
59
- *
60
- * **NOTE**: Support for client side encryption is in beta. Backwards-breaking changes may be made before the final release.
58
+ * Configuration options for drivers wrapping the node driver.
61
59
  *
62
- * @typedef {Object} AutoEncryptionOptions
63
- * @property {MongoClient} [keyVaultClient] A `MongoClient` used to fetch keys from a key vault
64
- * @property {string} [keyVaultNamespace] The namespace where keys are stored in the key vault
65
- * @property {object} [kmsProviders] Provider details for the desired Key Management Service to use for encryption
66
- * @property {object} [kmsProviders.aws] Optional settings for the AWS KMS provider
67
- * @property {string} [kmsProviders.aws.accessKeyId] The access key used for the AWS KMS provider
68
- * @property {string} [kmsProviders.aws.secretAccessKey] The secret access key used for the AWS KMS provider
69
- * @property {object} [kmsProviders.local] Optional settings for the local KMS provider
70
- * @property {string} [kmsProviders.local.key] The master key used to encrypt/decrypt data keys
71
- * @property {object} [schemaMap] A map of namespaces to a local JSON schema for encryption
72
- * @property {boolean} [bypassAutoEncryption] Allows the user to bypass auto encryption, maintaining implicit decryption
73
- * @property {object} [extraOptions] Extra options related to the mongocryptd process
74
- * @property {string} [extraOptions.mongocryptURI] A local process the driver communicates with to determine how to encrypt values in a command. Defaults to "mongodb://%2Fvar%2Fmongocryptd.sock" if domain sockets are available or "mongodb://localhost:27020" otherwise
75
- * @property {boolean} [extraOptions.mongocryptdBypassSpawn=false] If true, autoEncryption will not attempt to spawn a mongocryptd before connecting
76
- * @property {string} [extraOptions.mongocryptdSpawnPath] The path to the mongocryptd executable on the system
77
- * @property {string[]} [extraOptions.mongocryptdSpawnArgs] Command line arguments to use when auto-spawning a mongocryptd
60
+ * @typedef {Object} DriverInfoOptions
61
+ * @property {string} [name] The name of the driver
62
+ * @property {string} [version] The version of the driver
63
+ * @property {string} [platform] Optional platform information
78
64
  */
79
65
 
80
66
  /**
@@ -92,13 +78,21 @@ const CloseOperation = require('./operations/close');
92
78
  * @param {string} url The connection URI string
93
79
  * @param {object} [options] Optional settings
94
80
  * @param {number} [options.poolSize=5] The maximum size of the individual server pool
95
- * @param {boolean} [options.ssl=false] Enable SSL connection.
81
+ * @param {boolean} [options.ssl=false] Enable SSL connection. *deprecated* use `tls` variants
96
82
  * @param {boolean} [options.sslValidate=false] Validate mongod server certificate against Certificate Authority
97
- * @param {buffer} [options.sslCA=undefined] SSL Certificate store binary buffer
98
- * @param {buffer} [options.sslCert=undefined] SSL Certificate binary buffer
99
- * @param {buffer} [options.sslKey=undefined] SSL Key file binary buffer
100
- * @param {string} [options.sslPass=undefined] SSL Certificate pass phrase
101
- * @param {buffer} [options.sslCRL=undefined] SSL Certificate revocation list binary buffer
83
+ * @param {buffer} [options.sslCA=undefined] SSL Certificate store binary buffer *deprecated* use `tls` variants
84
+ * @param {buffer} [options.sslCert=undefined] SSL Certificate binary buffer *deprecated* use `tls` variants
85
+ * @param {buffer} [options.sslKey=undefined] SSL Key file binary buffer *deprecated* use `tls` variants
86
+ * @param {string} [options.sslPass=undefined] SSL Certificate pass phrase *deprecated* use `tls` variants
87
+ * @param {buffer} [options.sslCRL=undefined] SSL Certificate revocation list binary buffer *deprecated* use `tls` variants
88
+ * @param {boolean|function} [options.checkServerIdentity=true] Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function. *deprecated* use `tls` variants
89
+ * @param {boolean} [options.tls=false] Enable TLS connections
90
+ * @param {boolean} [options.tlsinsecure=false] Relax TLS constraints, disabling validation
91
+ * @param {string} [options.tlsCAFile] A path to file with either a single or bundle of certificate authorities to be considered trusted when making a TLS connection
92
+ * @param {string} [options.tlsCertificateKeyFile] A path to the client certificate file or the client private key file; in the case that they both are needed, the files should be concatenated
93
+ * @param {string} [options.tlsCertificateKeyFilePassword] The password to decrypt the client private key to be used for TLS connections
94
+ * @param {boolean} [options.tlsAllowInvalidCertificates] Specifies whether or not the driver should error when the server’s TLS certificate is invalid
95
+ * @param {boolean} [options.tlsAllowInvalidHostnames] Specifies whether or not the driver should error when there is a mismatch between the server’s hostname and the hostname specified by the TLS certificate
102
96
  * @param {boolean} [options.autoReconnect=true] Enable autoReconnect for single server instances
103
97
  * @param {boolean} [options.noDelay=true] TCP Connection no delay
104
98
  * @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled
@@ -136,7 +130,6 @@ const CloseOperation = require('./operations/close');
136
130
  * @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers
137
131
  * @param {boolean} [options.promoteLongs=true] Promotes long values to number if they fit inside the 53 bits resolution
138
132
  * @param {boolean} [options.domainsEnabled=false] Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit
139
- * @param {boolean|function} [options.checkServerIdentity=true] Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function
140
133
  * @param {object} [options.validateOptions=false] Validate MongoClient passed in options for correctness
141
134
  * @param {string} [options.appname=undefined] The name of the application that created this MongoClient instance. MongoDB 3.4 and newer will print this value in the server log upon establishing each connection. It is also recorded in the slow query log and profile collections
142
135
  * @param {string} [options.auth.user=undefined] The username for auth
@@ -151,7 +144,7 @@ const CloseOperation = require('./operations/close');
151
144
  * @param {number} [options.minSize] If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections
152
145
  * @param {boolean} [options.useNewUrlParser=true] Determines whether or not to use the new url parser. Enables the new, spec-compliant, url parser shipped in the core driver. This url parser fixes a number of problems with the original parser, and aims to outright replace that parser in the near future. Defaults to true, and must be explicitly set to false to use the legacy url parser.
153
146
  * @param {boolean} [options.useUnifiedTopology] Enables the new unified topology layer
154
- * @param {AutoEncryptionOptions} [options.autoEncryption] Optionally enable client side auto encryption
147
+ * @param {AutoEncrypter~AutoEncryptionOptions} [options.autoEncryption] Optionally enable client side auto encryption
155
148
  * @param {DriverInfoOptions} [options.driverInfo] Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver
156
149
  * @param {MongoClient~connectCallback} [callback] The command result callback
157
150
  * @return {MongoClient} a MongoClient instance
@@ -318,13 +311,21 @@ MongoClient.prototype.isConnected = function(options) {
318
311
  * @param {string} url The connection URI string
319
312
  * @param {object} [options] Optional settings
320
313
  * @param {number} [options.poolSize=5] The maximum size of the individual server pool
321
- * @param {boolean} [options.ssl=false] Enable SSL connection.
322
- * @param {boolean} [options.sslValidate=false] Validate mongod server certificate against Certificate Authority
323
- * @param {buffer} [options.sslCA=undefined] SSL Certificate store binary buffer
324
- * @param {buffer} [options.sslCert=undefined] SSL Certificate binary buffer
325
- * @param {buffer} [options.sslKey=undefined] SSL Key file binary buffer
326
- * @param {string} [options.sslPass=undefined] SSL Certificate pass phrase
327
- * @param {buffer} [options.sslCRL=undefined] SSL Certificate revocation list binary buffer
314
+ * @param {boolean} [options.ssl=false] Enable SSL connection. *deprecated* use `tls` variants
315
+ * @param {boolean} [options.sslValidate=false] Validate mongod server certificate against Certificate Authority *deprecated* use `tls` variants
316
+ * @param {buffer} [options.sslCA=undefined] SSL Certificate store binary buffer *deprecated* use `tls` variants
317
+ * @param {buffer} [options.sslCert=undefined] SSL Certificate binary buffer *deprecated* use `tls` variants
318
+ * @param {buffer} [options.sslKey=undefined] SSL Key file binary buffer *deprecated* use `tls` variants
319
+ * @param {string} [options.sslPass=undefined] SSL Certificate pass phrase *deprecated* use `tls` variants
320
+ * @param {buffer} [options.sslCRL=undefined] SSL Certificate revocation list binary buffer *deprecated* use `tls` variants
321
+ * @param {boolean|function} [options.checkServerIdentity=true] Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function. *deprecated* use `tls` variants
322
+ * @param {boolean} [options.tls=false] Enable TLS connections
323
+ * @param {boolean} [options.tlsinsecure=false] Relax TLS constraints, disabling validation
324
+ * @param {string} [options.tlsCAFile] A path to file with either a single or bundle of certificate authorities to be considered trusted when making a TLS connection
325
+ * @param {string} [options.tlsCertificateKeyFile] A path to the client certificate file or the client private key file; in the case that they both are needed, the files should be concatenated
326
+ * @param {string} [options.tlsCertificateKeyFilePassword] The password to decrypt the client private key to be used for TLS connections
327
+ * @param {boolean} [options.tlsAllowInvalidCertificates] Specifies whether or not the driver should error when the server’s TLS certificate is invalid
328
+ * @param {boolean} [options.tlsAllowInvalidHostnames] Specifies whether or not the driver should error when there is a mismatch between the server’s hostname and the hostname specified by the TLS certificate
328
329
  * @param {boolean} [options.autoReconnect=true] Enable autoReconnect for single server instances
329
330
  * @param {boolean} [options.noDelay=true] TCP Connection no delay
330
331
  * @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled
@@ -362,7 +363,6 @@ MongoClient.prototype.isConnected = function(options) {
362
363
  * @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers
363
364
  * @param {boolean} [options.promoteLongs=true] Promotes long values to number if they fit inside the 53 bits resolution
364
365
  * @param {boolean} [options.domainsEnabled=false] Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit
365
- * @param {boolean|function} [options.checkServerIdentity=true] Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function
366
366
  * @param {object} [options.validateOptions=false] Validate MongoClient passed in options for correctness
367
367
  * @param {string} [options.appname=undefined] The name of the application that created this MongoClient instance. MongoDB 3.4 and newer will print this value in the server log upon establishing each connection. It is also recorded in the slow query log and profile collections
368
368
  * @param {string} [options.auth.user=undefined] The username for auth
@@ -52,9 +52,7 @@ class CommandOperationV2 extends OperationBase {
52
52
  if (options.collation && serverWireVersion < SUPPORTS_WRITE_CONCERN_AND_COLLATION) {
53
53
  callback(
54
54
  new MongoError(
55
- `Server ${
56
- server.name
57
- }, which reports wire version ${serverWireVersion}, does not support collation`
55
+ `Server ${server.name}, which reports wire version ${serverWireVersion}, does not support collation`
58
56
  )
59
57
  );
60
58
  return;
@@ -183,8 +183,7 @@ function indexInformation(db, name, options, callback) {
183
183
  }
184
184
 
185
185
  // Get the list of indexes of the specified collection
186
- db
187
- .collection(name)
186
+ db.collection(name)
188
187
  .listIndexes(options)
189
188
  .toArray((err, indexes) => {
190
189
  if (err) return callback(toError(err));
@@ -16,6 +16,7 @@ const ReplSet = require('../topologies/replset');
16
16
  const Server = require('../topologies/server');
17
17
  const ServerSessionPool = require('../core').Sessions.ServerSessionPool;
18
18
  const emitDeprecationWarning = require('../utils').emitDeprecationWarning;
19
+ const fs = require('fs');
19
20
 
20
21
  let client;
21
22
  function loadClient() {
@@ -139,7 +140,15 @@ const validOptionNames = [
139
140
  'serverSelectionTimeoutMS',
140
141
  'useRecoveryToken',
141
142
  'autoEncryption',
142
- 'driverInfo'
143
+ 'driverInfo',
144
+ 'tls',
145
+ 'tlsinsecure',
146
+ 'tlsAllowInvalidCertificates',
147
+ 'tlsAllowInvalidHostnames',
148
+ 'tlsCAFile',
149
+ 'tlsCertificateFile',
150
+ 'tlsCertificateKeyFile',
151
+ 'tlsCertificateKeyFilePassword'
143
152
  ];
144
153
 
145
154
  const ignoreOptionNames = ['native_parser'];
@@ -243,6 +252,18 @@ function collectEvents(mongoClient, topology) {
243
252
  return collectedEvents;
244
253
  }
245
254
 
255
+ function resolveTLSOptions(options) {
256
+ if (options.tls == null) {
257
+ return;
258
+ }
259
+
260
+ ['sslCA', 'sslKey', 'sslCert'].forEach(optionName => {
261
+ if (options[optionName]) {
262
+ options[optionName] = fs.readFileSync(options[optionName]);
263
+ }
264
+ });
265
+ }
266
+
246
267
  const emitDeprecationForNonUnifiedTopology = deprecate(() => {},
247
268
  'current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. ' + 'To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.');
248
269
 
@@ -288,6 +309,9 @@ function connect(mongoClient, url, options, callback) {
288
309
  delete _finalOptions.db_options.auth;
289
310
  }
290
311
 
312
+ // resolve tls options if needed
313
+ resolveTLSOptions(_finalOptions);
314
+
291
315
  // Store the merged options object
292
316
  mongoClient.s.options = _finalOptions;
293
317
 
@@ -504,7 +528,13 @@ function createTopology(mongoClient, topologyType, options, callback) {
504
528
  return;
505
529
  }
506
530
  try {
507
- AutoEncrypter = require('mongodb-client-encryption')(require('../../index')).AutoEncrypter;
531
+ let mongodbClientEncryption = require('mongodb-client-encryption');
532
+ if (typeof mongodbClientEncryption.extension !== 'function') {
533
+ throw new MongoError(
534
+ 'loaded version of `mongodb-client-encryption` does not have property `extension`. Please make sure you are loading the correct version of `mongodb-client-encryption`'
535
+ );
536
+ }
537
+ AutoEncrypter = mongodbClientEncryption.extension(require('../../index')).AutoEncrypter;
508
538
  } catch (err) {
509
539
  callback(err);
510
540
  return;
@@ -530,7 +560,7 @@ function createUnifiedOptions(finalOptions, options) {
530
560
  'rs_options',
531
561
  'mongos_options'
532
562
  ];
533
- const noMerge = ['readconcern', 'compression'];
563
+ const noMerge = ['readconcern', 'compression', 'autoencryption'];
534
564
 
535
565
  for (const name in options) {
536
566
  if (noMerge.indexOf(name.toLowerCase()) !== -1) {
@@ -69,8 +69,7 @@ class CreateCollectionOperation extends CommandOperation {
69
69
  listCollectionOptions = applyWriteConcern(listCollectionOptions, { db }, listCollectionOptions);
70
70
 
71
71
  // Check if we have the name
72
- db
73
- .listCollections({ name }, listCollectionOptions)
72
+ db.listCollections({ name }, listCollectionOptions)
74
73
  .setReadPreference(ReadPreference.PRIMARY)
75
74
  .toArray((err, collections) => {
76
75
  if (err != null) return handleCallback(callback, err, null);
@@ -474,8 +474,7 @@ function indexInformation(db, name, options, callback) {
474
474
  }
475
475
 
476
476
  // Get the list of indexes of the specified collection
477
- db
478
- .collection(name)
477
+ db.collection(name)
479
478
  .listIndexes(options)
480
479
  .toArray((err, indexes) => {
481
480
  if (err) return callback(toError(err));
@@ -496,8 +495,7 @@ function indexInformation(db, name, options, callback) {
496
495
  */
497
496
  function profilingInfo(db, options, callback) {
498
497
  try {
499
- db
500
- .collection('system.profile')
498
+ db.collection('system.profile')
501
499
  .find({}, options)
502
500
  .toArray(callback);
503
501
  } catch (err) {
@@ -155,7 +155,8 @@ function executeWithServerSelection(topology, operation, callback) {
155
155
 
156
156
  const shouldRetryReads =
157
157
  topology.s.options.retryReads !== false &&
158
- (operation.session && !inTransaction) &&
158
+ operation.session &&
159
+ !inTransaction &&
159
160
  supportsRetryableReads(server) &&
160
161
  operation.canRetryRead;
161
162
 
@@ -87,7 +87,8 @@ class MapReduceOperation extends OperationBase {
87
87
  options.readPreference !== false &&
88
88
  options.readPreference !== 'primary' &&
89
89
  options['out'] &&
90
- (options['out'].inline !== 1 && options['out'] !== 'inline')
90
+ options['out'].inline !== 1 &&
91
+ options['out'] !== 'inline'
91
92
  ) {
92
93
  // Force readPreference to primary
93
94
  options.readPreference = 'primary';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb",
3
- "version": "3.3.5",
3
+ "version": "3.4.0",
4
4
  "description": "The official MongoDB driver for Node.js",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -30,6 +30,7 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "bluebird": "3.5.0",
33
+ "bl": "^2.2.0",
33
34
  "chai": "^4.1.1",
34
35
  "chai-subset": "^1.6.0",
35
36
  "chalk": "^2.4.2",
@@ -44,15 +45,15 @@
44
45
  "mocha-sinon": "^2.1.0",
45
46
  "mongodb-extjson": "^2.1.1",
46
47
  "mongodb-mock-server": "^1.0.1",
47
- "prettier": "~1.12.0",
48
+ "prettier": "^1.19.1",
48
49
  "semver": "^5.5.0",
49
50
  "sinon": "^4.3.0",
50
51
  "sinon-chai": "^3.2.0",
51
52
  "snappy": "^6.1.2",
52
53
  "standard-version": "^4.4.0",
53
- "yargs": "^14.2.0",
54
54
  "worker-farm": "^1.5.0",
55
- "wtfnode": "^0.8.0"
55
+ "wtfnode": "^0.8.0",
56
+ "yargs": "^14.2.0"
56
57
  },
57
58
  "license": "Apache-2.0",
58
59
  "engines": {
@@ -62,13 +63,13 @@
62
63
  "url": "https://github.com/mongodb/node-mongodb-native/issues"
63
64
  },
64
65
  "scripts": {
65
- "atlas": "node ./test/atlas_connectivity_tests.js",
66
+ "atlas": "node ./test/tools/atlas_connectivity_tests.js",
66
67
  "test": "npm run lint && mocha --recursive test/functional test/unit test/core",
67
68
  "test-nolint": "mocha --recursive test/functional test/unit test/core",
68
69
  "coverage": "istanbul cover mongodb-test-runner -- -t 60000 test/core test/unit test/functional",
69
70
  "lint": "eslint lib test",
70
71
  "format": "prettier --print-width 100 --tab-width 2 --single-quote --write 'test/**/*.js' 'lib/**/*.js'",
71
- "bench": "node test/driverBench/",
72
+ "bench": "node test/benchmarks/driverBench/",
72
73
  "generate-evergreen": "node .evergreen/generate_evergreen_tasks.js",
73
74
  "release": "standard-version -i HISTORY.md"
74
75
  },