mongodb 3.5.11 → 3.6.2

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 (68) hide show
  1. package/HISTORY.md +42 -21
  2. package/lib/admin.js +1 -0
  3. package/lib/bulk/common.js +48 -4
  4. package/lib/change_stream.js +0 -1
  5. package/lib/cmap/connection.js +9 -6
  6. package/lib/cmap/connection_pool.js +4 -10
  7. package/lib/collection.js +59 -81
  8. package/lib/core/auth/auth_provider.js +29 -132
  9. package/lib/core/auth/defaultAuthProviders.js +2 -2
  10. package/lib/core/auth/gssapi.js +124 -214
  11. package/lib/core/auth/mongo_credentials.js +29 -3
  12. package/lib/core/auth/mongocr.js +6 -12
  13. package/lib/core/auth/mongodb_aws.js +256 -0
  14. package/lib/core/auth/plain.js +5 -12
  15. package/lib/core/auth/scram.js +229 -212
  16. package/lib/core/auth/x509.js +25 -16
  17. package/lib/core/connection/connect.js +97 -161
  18. package/lib/core/connection/connection.js +71 -3
  19. package/lib/core/connection/pool.js +2 -2
  20. package/lib/core/cursor.js +18 -11
  21. package/lib/core/error.js +82 -8
  22. package/lib/core/sdam/common.js +8 -0
  23. package/lib/core/sdam/monitor.js +240 -78
  24. package/lib/core/sdam/server.js +81 -15
  25. package/lib/core/sdam/server_description.js +37 -2
  26. package/lib/core/sdam/topology.js +41 -8
  27. package/lib/core/sdam/topology_description.js +21 -3
  28. package/lib/core/sessions.js +38 -51
  29. package/lib/core/topologies/mongos.js +18 -6
  30. package/lib/core/topologies/read_preference.js +15 -3
  31. package/lib/core/topologies/replset.js +4 -4
  32. package/lib/core/topologies/server.js +1 -1
  33. package/lib/core/topologies/shared.js +39 -16
  34. package/lib/core/uri_parser.js +41 -6
  35. package/lib/core/utils.js +30 -0
  36. package/lib/core/wireprotocol/command.js +1 -4
  37. package/lib/core/wireprotocol/constants.js +2 -2
  38. package/lib/core/wireprotocol/query.js +4 -0
  39. package/lib/cursor.js +0 -1
  40. package/lib/db.js +6 -5
  41. package/lib/error.js +6 -1
  42. package/lib/gridfs-stream/download.js +13 -2
  43. package/lib/mongo_client.js +6 -4
  44. package/lib/operations/collection_ops.js +0 -20
  45. package/lib/operations/command_v2.js +1 -1
  46. package/lib/operations/common_functions.js +3 -0
  47. package/lib/operations/connect.js +11 -14
  48. package/lib/operations/create_collection.js +37 -52
  49. package/lib/operations/create_indexes.js +111 -35
  50. package/lib/operations/find.js +7 -1
  51. package/lib/operations/find_and_modify.js +17 -0
  52. package/lib/operations/find_one_and_delete.js +5 -0
  53. package/lib/operations/find_one_and_replace.js +13 -0
  54. package/lib/operations/find_one_and_update.js +13 -0
  55. package/lib/operations/map_reduce.js +1 -1
  56. package/lib/operations/re_index.js +22 -17
  57. package/lib/operations/replace_one.js +11 -4
  58. package/lib/operations/update_many.js +5 -0
  59. package/lib/operations/update_one.js +5 -0
  60. package/lib/operations/validate_collection.js +1 -2
  61. package/lib/topologies/mongos.js +1 -1
  62. package/lib/topologies/replset.js +1 -1
  63. package/lib/topologies/server.js +1 -1
  64. package/lib/utils.js +18 -1
  65. package/lib/write_concern.js +10 -0
  66. package/package.json +1 -1
  67. package/lib/core/auth/sspi.js +0 -131
  68. package/lib/operations/create_index.js +0 -92
package/HISTORY.md CHANGED
@@ -2,47 +2,69 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- <a name="3.5.11"></a>
6
- ## [3.5.11](https://github.com/mongodb/node-mongodb-native/compare/v3.5.10...v3.5.11) (2020-09-10)
5
+ <a name="3.6.2"></a>
6
+ ## [3.6.2](https://github.com/mongodb/node-mongodb-native/compare/v3.6.1...v3.6.2) (2020-09-10)
7
7
 
8
8
 
9
9
  ### Bug Fixes
10
10
 
11
- * add host/port to cmap connection ([07b2b0d](https://github.com/mongodb/node-mongodb-native/commit/07b2b0d))
11
+ * allow event loop to process during wait queue processing ([#2537](https://github.com/mongodb/node-mongodb-native/issues/2537)) ([4e03dfa](https://github.com/mongodb/node-mongodb-native/commit/4e03dfa))
12
12
 
13
13
 
14
14
 
15
- <a name="3.5.9"></a>
16
- ## [3.5.9](https://github.com/mongodb/node-mongodb-native/compare/v3.5.8...v3.5.9) (2020-06-12)
15
+ <a name="3.6.1"></a>
16
+ ## [3.6.1](https://github.com/mongodb/node-mongodb-native/compare/v3.6.0...v3.6.1) (2020-09-02)
17
17
 
18
18
 
19
19
  ### Bug Fixes
20
20
 
21
- * don't try to calculate sMax if there are no viable servers ([be51347](https://github.com/mongodb/node-mongodb-native/commit/be51347))
22
- * use async interruptable interval for server monitoring ([1f855a4](https://github.com/mongodb/node-mongodb-native/commit/1f855a4))
23
- * use duration of handshake if no previous roundTripTime exists ([ddfa41b](https://github.com/mongodb/node-mongodb-native/commit/ddfa41b))
21
+ * add host/port to cmap connection ([06a2444](https://github.com/mongodb/node-mongodb-native/commit/06a2444))
22
+ * update full list of index options ([0af3191](https://github.com/mongodb/node-mongodb-native/commit/0af3191))
24
23
 
25
24
 
26
25
  ### Features
27
26
 
28
- * introduce an interruptable async interval timer ([9e12cd5](https://github.com/mongodb/node-mongodb-native/commit/9e12cd5))
27
+ * **db:** deprecate createCollection strict mode ([4cc6bcc](https://github.com/mongodb/node-mongodb-native/commit/4cc6bcc))
29
28
 
30
29
 
31
30
 
32
- <a name="3.5.8"></a>
33
- ## [3.5.8](https://github.com/mongodb/node-mongodb-native/compare/v3.5.7...v3.5.8) (2020-05-28)
34
-
31
+ <a name="3.6.0-beta.0"></a>
32
+ # [3.6.0-beta.0](https://github.com/mongodb/node-mongodb-native/compare/v3.5.5...v3.6.0-beta.0) (2020-04-14)
35
33
 
36
34
  ### Bug Fixes
37
35
 
38
- * always clear cancelled wait queue members during processing ([0394f9d](https://github.com/mongodb/node-mongodb-native/commit/0394f9d))
39
- * always include `writeErrors` on a `BulkWriteError` instance ([58b4f94](https://github.com/mongodb/node-mongodb-native/commit/58b4f94))
40
- * ensure implicit sessions are ended consistently ([5c6fda1](https://github.com/mongodb/node-mongodb-native/commit/5c6fda1))
41
- * filter servers before applying reducers ([4faf9f5](https://github.com/mongodb/node-mongodb-native/commit/4faf9f5))
42
- * unordered bulk write should attempt to execute all batches ([6cee96b](https://github.com/mongodb/node-mongodb-native/commit/6cee96b))
43
- * **ChangeStream:** should resume from errors when iterating ([5ecf18e](https://github.com/mongodb/node-mongodb-native/commit/5ecf18e))
44
- * honor journal=true in connection string ([#2359](https://github.com/mongodb/node-mongodb-native/issues/2359)) ([246669f](https://github.com/mongodb/node-mongodb-native/commit/246669f))
45
- * **ChangeStream:** whitelist resumable errors ([#2337](https://github.com/mongodb/node-mongodb-native/issues/2337)) ([a9d3965](https://github.com/mongodb/node-mongodb-native/commit/a9d3965)), closes [#17](https://github.com/mongodb/node-mongodb-native/issues/17) [#18](https://github.com/mongodb/node-mongodb-native/issues/18)
36
+ * always return empty array for selection on unknown topology ([af57b57](https://github.com/mongodb/node-mongodb-native/commit/af57b57))
37
+ * always return empty array for selection on unknown topology ([f9e786a](https://github.com/mongodb/node-mongodb-native/commit/f9e786a))
38
+ * correctly use template string for connection string error message ([814e278](https://github.com/mongodb/node-mongodb-native/commit/814e278))
39
+ * createCollection only uses listCollections in strict mode ([d368f12](https://github.com/mongodb/node-mongodb-native/commit/d368f12))
40
+ * don't depend on private node api for `Timeout` wrapper ([e6dc1f4](https://github.com/mongodb/node-mongodb-native/commit/e6dc1f4))
41
+ * don't throw if `withTransaction()` callback rejects with a null reason ([153646c](https://github.com/mongodb/node-mongodb-native/commit/153646c))
42
+ * **cursor:** transforms should only be applied once to documents ([704f30a](https://github.com/mongodb/node-mongodb-native/commit/704f30a))
43
+ * only consider MongoError subclasses for retryability ([265fe40](https://github.com/mongodb/node-mongodb-native/commit/265fe40))
44
+ * **ChangeStream:** whitelist change stream resumable errors ([8a9c108](https://github.com/mongodb/node-mongodb-native/commit/8a9c108)), closes [#17](https://github.com/mongodb/node-mongodb-native/issues/17) [#18](https://github.com/mongodb/node-mongodb-native/issues/18)
45
+ * **sdam:** use ObjectId comparison to track maxElectionId ([db991d6](https://github.com/mongodb/node-mongodb-native/commit/db991d6))
46
+ * only mark server session dirty if the client session is alive ([611be8d](https://github.com/mongodb/node-mongodb-native/commit/611be8d))
47
+ * pass options into `commandSupportsReadConcern` ([e855c83](https://github.com/mongodb/node-mongodb-native/commit/e855c83))
48
+ * polyfill for util.promisify ([1c4cf6c](https://github.com/mongodb/node-mongodb-native/commit/1c4cf6c))
49
+ * single `readPreferenceTags` should be parsed as an array ([a50611b](https://github.com/mongodb/node-mongodb-native/commit/a50611b))
50
+ * store name of collection for more informative error messages ([979d41e](https://github.com/mongodb/node-mongodb-native/commit/979d41e))
51
+ * support write concern provided as string in `fromOptions` ([637f428](https://github.com/mongodb/node-mongodb-native/commit/637f428))
52
+ * use properly camel cased form of `mapReduce` for command ([c1ed2c1](https://github.com/mongodb/node-mongodb-native/commit/c1ed2c1))
53
+
54
+
55
+ ### Features
56
+
57
+ * add MONGODB-AWS as a supported auth mechanism ([7f3cfba](https://github.com/mongodb/node-mongodb-native/commit/7f3cfba))
58
+ * bump wire protocol version for 4.4 ([6d3f313](https://github.com/mongodb/node-mongodb-native/commit/6d3f313))
59
+ * deprecate `oplogReplay` for find commands ([24155e7](https://github.com/mongodb/node-mongodb-native/commit/24155e7))
60
+ * directConnection adds unify behavior for replica set discovery ([c5d60fc](https://github.com/mongodb/node-mongodb-native/commit/c5d60fc))
61
+ * expand use of error labels for retryable writes ([c775a4a](https://github.com/mongodb/node-mongodb-native/commit/c775a4a))
62
+ * support `allowDiskUse` for find commands ([dbc0b37](https://github.com/mongodb/node-mongodb-native/commit/dbc0b37))
63
+ * support creating collections and indexes in transactions ([17e4c88](https://github.com/mongodb/node-mongodb-native/commit/17e4c88))
64
+ * support passing a hint to findOneAndReplace/findOneAndUpdate ([faee15b](https://github.com/mongodb/node-mongodb-native/commit/faee15b))
65
+ * support shorter SCRAM conversations ([6b9ff05](https://github.com/mongodb/node-mongodb-native/commit/6b9ff05))
66
+ * use error labels for retryable writes in legacy topologies ([fefc165](https://github.com/mongodb/node-mongodb-native/commit/fefc165))
67
+
46
68
 
47
69
 
48
70
 
@@ -60,7 +82,6 @@ All notable changes to this project will be documented in this file. See [standa
60
82
  <a name="3.5.6"></a>
61
83
  ## [3.5.6](https://github.com/mongodb/node-mongodb-native/compare/v3.5.5...v3.5.6) (2020-04-14)
62
84
 
63
-
64
85
  ### Bug Fixes
65
86
 
66
87
  * always return empty array for selection on unknown topology ([f9e786a](https://github.com/mongodb/node-mongodb-native/commit/f9e786a))
package/lib/admin.js CHANGED
@@ -232,6 +232,7 @@ Admin.prototype.removeUser = function(username, options, callback) {
232
232
  *
233
233
  * @param {string} collectionName The name of the collection to validate.
234
234
  * @param {object} [options] Optional settings.
235
+ * @param {boolean} [options.background] Validates a collection in the background, without interrupting read or write traffic (only in MongoDB 4.4+)
235
236
  * @param {ClientSession} [options.session] optional session to use for this operation
236
237
  * @param {Admin~resultCallback} [callback] The command result callback.
237
238
  * @return {Promise} returns Promise if no callback passed
@@ -11,6 +11,8 @@ const applyRetryableWrites = require('../utils').applyRetryableWrites;
11
11
  const applyWriteConcern = require('../utils').applyWriteConcern;
12
12
  const executeLegacyOperation = require('../utils').executeLegacyOperation;
13
13
  const isPromiseLike = require('../utils').isPromiseLike;
14
+ const hasAtomicOperators = require('../utils').hasAtomicOperators;
15
+ const maxWireVersion = require('../core/utils').maxWireVersion;
14
16
 
15
17
  // Error codes
16
18
  const WRITE_CONCERN_ERROR = 64;
@@ -641,6 +643,10 @@ class FindOperators {
641
643
  document.hint = updateDocument.hint;
642
644
  }
643
645
 
646
+ if (!hasAtomicOperators(updateDocument)) {
647
+ throw new TypeError('Update document requires atomic operators');
648
+ }
649
+
644
650
  // Clear out current Op
645
651
  this.s.currentOp = null;
646
652
  return this.s.options.addToOperationsList(this, UPDATE, document);
@@ -650,12 +656,33 @@ class FindOperators {
650
656
  * Add a replace one operation to the bulk operation
651
657
  *
652
658
  * @method
653
- * @param {object} updateDocument the new document to replace the existing one with
659
+ * @param {object} replacement the new document to replace the existing one with
654
660
  * @throws {MongoError} If operation cannot be added to bulk write
655
661
  * @return {OrderedBulkOperation|UnorderedBulkOperation} A reference to the parent BulkOperation
656
662
  */
657
- replaceOne(updateDocument) {
658
- this.updateOne(updateDocument);
663
+ replaceOne(replacement) {
664
+ // Perform upsert
665
+ const upsert = typeof this.s.currentOp.upsert === 'boolean' ? this.s.currentOp.upsert : false;
666
+
667
+ // Establish the update command
668
+ const document = {
669
+ q: this.s.currentOp.selector,
670
+ u: replacement,
671
+ multi: false,
672
+ upsert: upsert
673
+ };
674
+
675
+ if (replacement.hint) {
676
+ document.hint = replacement.hint;
677
+ }
678
+
679
+ if (hasAtomicOperators(replacement)) {
680
+ throw new TypeError('Replacement document must not use atomic operators');
681
+ }
682
+
683
+ // Clear out current Op
684
+ this.s.currentOp = null;
685
+ return this.s.options.addToOperationsList(this, UPDATE, document);
659
686
  }
660
687
 
661
688
  /**
@@ -943,6 +970,12 @@ class BulkOperationBase {
943
970
 
944
971
  // Crud spec update format
945
972
  if (op.updateOne || op.updateMany || op.replaceOne) {
973
+ if (op.replaceOne && hasAtomicOperators(op[key].replacement)) {
974
+ throw new TypeError('Replacement document must not use atomic operators');
975
+ } else if ((op.updateOne || op.updateMany) && !hasAtomicOperators(op[key].update)) {
976
+ throw new TypeError('Update document requires atomic operators');
977
+ }
978
+
946
979
  const multi = op.updateOne || op.replaceOne ? false : true;
947
980
  const operation = {
948
981
  q: op[key].filter,
@@ -960,7 +993,15 @@ class BulkOperationBase {
960
993
  } else {
961
994
  if (op[key].upsert) operation.upsert = true;
962
995
  }
963
- if (op[key].arrayFilters) operation.arrayFilters = op[key].arrayFilters;
996
+ if (op[key].arrayFilters) {
997
+ // TODO: this check should be done at command construction against a connection, not a topology
998
+ if (maxWireVersion(this.s.topology) < 6) {
999
+ throw new TypeError('arrayFilters are only supported on MongoDB 3.6+');
1000
+ }
1001
+
1002
+ operation.arrayFilters = op[key].arrayFilters;
1003
+ }
1004
+
964
1005
  return this.s.options.addToOperationsList(this, UPDATE, operation);
965
1006
  }
966
1007
 
@@ -979,6 +1020,9 @@ class BulkOperationBase {
979
1020
  if (op.deleteOne || op.deleteMany) {
980
1021
  const limit = op.deleteOne ? 1 : 0;
981
1022
  const operation = { q: op[key].filter, limit: limit };
1023
+ if (op[key].hint) {
1024
+ operation.hint = op[key].hint;
1025
+ }
982
1026
  if (this.isOrdered) {
983
1027
  if (op.collation) operation.collation = op.collation;
984
1028
  }
@@ -169,7 +169,6 @@ class ChangeStream extends EventEmitter {
169
169
  /**
170
170
  * Is the change stream closed
171
171
  * @method ChangeStream.prototype.isClosed
172
- * @param {boolean} [checkCursor=true] also check if the underlying cursor is closed
173
172
  * @return {boolean}
174
173
  */
175
174
  isClosed() {
@@ -4,6 +4,7 @@ const EventEmitter = require('events');
4
4
  const MessageStream = require('./message_stream');
5
5
  const MongoError = require('../core/error').MongoError;
6
6
  const MongoNetworkError = require('../core/error').MongoNetworkError;
7
+ const MongoNetworkTimeoutError = require('../core/error').MongoNetworkTimeoutError;
7
8
  const MongoWriteConcernError = require('../core/error').MongoWriteConcernError;
8
9
  const CommandResult = require('../core/connection/command_result');
9
10
  const StreamDescription = require('./stream_description').StreamDescription;
@@ -79,10 +80,14 @@ class Connection extends EventEmitter {
79
80
  stream.destroy();
80
81
  this.closed = true;
81
82
  this[kQueue].forEach(op =>
82
- op.cb(new MongoNetworkError(`connection ${this.id} to ${this.address} timed out`))
83
+ op.cb(
84
+ new MongoNetworkTimeoutError(`connection ${this.id} to ${this.address} timed out`, {
85
+ beforeHandshake: this[kIsMaster] == null
86
+ })
87
+ )
83
88
  );
84
- this[kQueue].clear();
85
89
 
90
+ this[kQueue].clear();
86
91
  this.emit('close');
87
92
  });
88
93
 
@@ -220,6 +225,7 @@ function messageHandler(conn) {
220
225
  }
221
226
 
222
227
  const operationDescription = conn[kQueue].get(message.responseTo);
228
+ const callback = operationDescription.cb;
223
229
 
224
230
  // SERVER-45775: For exhaust responses we should be able to use the same requestId to
225
231
  // track response, however the server currently synthetically produces remote requests
@@ -228,10 +234,7 @@ function messageHandler(conn) {
228
234
  if (message.moreToCome) {
229
235
  // requeue the callback for next synthetic request
230
236
  conn[kQueue].set(message.requestId, operationDescription);
231
- }
232
-
233
- const callback = operationDescription.cb;
234
- if (operationDescription.socketTimeoutOverride) {
237
+ } else if (operationDescription.socketTimeoutOverride) {
235
238
  conn[kStream].setTimeout(conn.socketTimeout);
236
239
  }
237
240
 
@@ -218,7 +218,6 @@ class ConnectionPool extends EventEmitter {
218
218
  return;
219
219
  }
220
220
 
221
- // add this request to the wait queue
222
221
  const waitQueueMember = { callback };
223
222
 
224
223
  const pool = this;
@@ -233,11 +232,8 @@ class ConnectionPool extends EventEmitter {
233
232
  }, waitQueueTimeoutMS);
234
233
  }
235
234
 
236
- // place the member at the end of the wait queue
237
235
  this[kWaitQueue].push(waitQueueMember);
238
-
239
- // process the wait queue
240
- processWaitQueue(this);
236
+ setImmediate(() => processWaitQueue(this));
241
237
  }
242
238
 
243
239
  /**
@@ -250,10 +246,8 @@ class ConnectionPool extends EventEmitter {
250
246
  const stale = connectionIsStale(this, connection);
251
247
  const willDestroy = !!(poolClosed || stale || connection.closed);
252
248
 
253
- // Properly adjust state of connection
254
249
  if (!willDestroy) {
255
250
  connection.markAvailable();
256
-
257
251
  this[kConnections].push(connection);
258
252
  }
259
253
 
@@ -264,7 +258,7 @@ class ConnectionPool extends EventEmitter {
264
258
  destroyConnection(this, connection, reason);
265
259
  }
266
260
 
267
- processWaitQueue(this);
261
+ setImmediate(() => processWaitQueue(this));
268
262
  }
269
263
 
270
264
  /**
@@ -434,7 +428,7 @@ function createConnection(pool, callback) {
434
428
 
435
429
  // otherwise add it to the pool for later acquisition, and try to process the wait queue
436
430
  pool[kConnections].push(connection);
437
- processWaitQueue(pool);
431
+ setImmediate(() => processWaitQueue(pool));
438
432
  });
439
433
  }
440
434
 
@@ -445,7 +439,7 @@ function destroyConnection(pool, connection, reason) {
445
439
  pool[kPermits]++;
446
440
 
447
441
  // destroy the connection
448
- process.nextTick(() => connection.destroy());
442
+ setImmediate(() => connection.destroy());
449
443
  }
450
444
 
451
445
  function processWaitQueue(pool) {