mongodb 3.5.9 → 3.6.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 (73) hide show
  1. package/HISTORY.md +110 -18
  2. package/lib/admin.js +1 -0
  3. package/lib/bulk/common.js +48 -4
  4. package/lib/change_stream.js +7 -3
  5. package/lib/cmap/connection.js +9 -6
  6. package/lib/collection.js +61 -84
  7. package/lib/core/auth/auth_provider.js +29 -132
  8. package/lib/core/auth/defaultAuthProviders.js +2 -2
  9. package/lib/core/auth/gssapi.js +69 -219
  10. package/lib/core/auth/mongo_credentials.js +29 -3
  11. package/lib/core/auth/mongocr.js +6 -12
  12. package/lib/core/auth/mongodb_aws.js +256 -0
  13. package/lib/core/auth/plain.js +5 -12
  14. package/lib/core/auth/scram.js +229 -212
  15. package/lib/core/auth/x509.js +25 -16
  16. package/lib/core/connection/connect.js +97 -161
  17. package/lib/core/connection/connection.js +71 -3
  18. package/lib/core/connection/pool.js +2 -2
  19. package/lib/core/cursor.js +30 -39
  20. package/lib/core/error.js +82 -8
  21. package/lib/core/sdam/common.js +8 -0
  22. package/lib/core/sdam/monitor.js +240 -79
  23. package/lib/core/sdam/server.js +82 -17
  24. package/lib/core/sdam/server_description.js +47 -2
  25. package/lib/core/sdam/topology.js +43 -32
  26. package/lib/core/sdam/topology_description.js +21 -3
  27. package/lib/core/sessions.js +14 -16
  28. package/lib/core/topologies/mongos.js +18 -6
  29. package/lib/core/topologies/read_preference.js +71 -7
  30. package/lib/core/topologies/replset.js +4 -4
  31. package/lib/core/topologies/server.js +1 -1
  32. package/lib/core/topologies/shared.js +39 -16
  33. package/lib/core/uri_parser.js +41 -6
  34. package/lib/core/utils.js +30 -0
  35. package/lib/core/wireprotocol/command.js +2 -10
  36. package/lib/core/wireprotocol/constants.js +2 -2
  37. package/lib/core/wireprotocol/query.js +4 -0
  38. package/lib/cursor.js +0 -1
  39. package/lib/db.js +7 -6
  40. package/lib/error.js +6 -1
  41. package/lib/gridfs-stream/download.js +13 -2
  42. package/lib/mongo_client.js +6 -4
  43. package/lib/operations/collection_ops.js +1 -22
  44. package/lib/operations/command.js +2 -3
  45. package/lib/operations/command_v2.js +8 -7
  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 +91 -35
  50. package/lib/operations/db_ops.js +1 -2
  51. package/lib/operations/find.js +9 -3
  52. package/lib/operations/find_and_modify.js +17 -0
  53. package/lib/operations/find_one_and_delete.js +5 -0
  54. package/lib/operations/find_one_and_replace.js +13 -0
  55. package/lib/operations/find_one_and_update.js +13 -0
  56. package/lib/operations/geo_haystack_search.js +2 -2
  57. package/lib/operations/map_reduce.js +3 -3
  58. package/lib/operations/operation.js +2 -1
  59. package/lib/operations/re_index.js +22 -17
  60. package/lib/operations/replace_one.js +11 -4
  61. package/lib/operations/run_command.js +19 -0
  62. package/lib/operations/update_many.js +5 -0
  63. package/lib/operations/update_one.js +5 -0
  64. package/lib/operations/validate_collection.js +1 -2
  65. package/lib/topologies/mongos.js +1 -1
  66. package/lib/topologies/replset.js +1 -1
  67. package/lib/topologies/server.js +1 -1
  68. package/lib/topologies/topology_base.js +4 -4
  69. package/lib/utils.js +18 -60
  70. package/lib/write_concern.js +10 -0
  71. package/package.json +2 -2
  72. package/lib/core/auth/sspi.js +0 -131
  73. package/lib/operations/create_index.js +0 -92
package/HISTORY.md CHANGED
@@ -1,38 +1,131 @@
1
- # Change Log
1
+ # Changelog
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.9"></a>
6
- ## [3.5.9](https://github.com/mongodb/node-mongodb-native/compare/v3.5.8...v3.5.9) (2020-06-12)
5
+ ## [3.6.0](https://github.com/mongodb/node-mongodb-native/compare/v3.5.7...v3.6.0) (2020-07-30)
6
+
7
+
8
+ ### Features
9
+
10
+ * add commitQuorum option to createIndexes command ([38bcaf7](https://github.com/mongodb/node-mongodb-native/commit/38bcaf7c80f63885d4c0cf1f7389819efb0664e6))
11
+ * introduce an interruptable async interval timer ([1e4e837](https://github.com/mongodb/node-mongodb-native/commit/1e4e8373308a6d99c4d7eda4ae395f8293de98eb))
12
+ * support streaming ismaster responses ([f6629d9](https://github.com/mongodb/node-mongodb-native/commit/f6629d9946d6d02012a6f1f7848306bc71fb3254))
13
+ * **reIndex:** deprecate and make standalone-only command ([3a53b3d](https://github.com/mongodb/node-mongodb-native/commit/3a53b3deb7b375f6ce1e1a7435706aa4df7b0a0c))
14
+ * add helper to run async collection in series ([f762532](https://github.com/mongodb/node-mongodb-native/commit/f76253242a9b9c3d1fc5be215e8b677af2138772))
15
+ * allow hinting the delete command ([84cf955](https://github.com/mongodb/node-mongodb-native/commit/84cf95519d55e478b6457ba2347daf448388caf2))
16
+ * consider staleness and topologyVersion in error handling ([018e6ed](https://github.com/mongodb/node-mongodb-native/commit/018e6edc923f1bb7aa13bf376edd71172bfc5039))
17
+ * introduce `MongoNetworkTimeoutError` ([c1e4477](https://github.com/mongodb/node-mongodb-native/commit/c1e44777f9ede629290bb776c420018a4acdc487))
18
+ * support checking if network error happened before handshake ([5411786](https://github.com/mongodb/node-mongodb-native/commit/541178690d558a4484d43d2a090d0b4d5416c031))
19
+ * support hedged reads ([37cd5ee](https://github.com/mongodb/node-mongodb-native/commit/37cd5eed9f872429f3d0f683ed92cc75231d4685))
20
+ * support speculative authentication in scram-sha and x509 ([6231164](https://github.com/mongodb/node-mongodb-native/commit/62311645c5e9a44678e4a997b6a5944b64492bd8))
21
+ * **geoHaystackSearch:** deprecate geoHaystackSearch ([3f6786b](https://github.com/mongodb/node-mongodb-native/commit/3f6786b4c00d0650eb9c8009507e9c54b2b11bbc))
22
+ * **sdam:** ignore stale topology updates ([f87d243](https://github.com/mongodb/node-mongodb-native/commit/f87d243587c1712cd95624d036ddb9a643a15a84))
7
23
 
8
24
 
9
25
  ### Bug Fixes
10
26
 
11
- * don't try to calculate sMax if there are no viable servers ([be51347](https://github.com/mongodb/node-mongodb-native/commit/be51347))
12
- * use async interruptable interval for server monitoring ([1f855a4](https://github.com/mongodb/node-mongodb-native/commit/1f855a4))
13
- * use duration of handshake if no previous roundTripTime exists ([ddfa41b](https://github.com/mongodb/node-mongodb-native/commit/ddfa41b))
27
+ * `resolveAuthMechanism` should not mutate credentials ([be19a21](https://github.com/mongodb/node-mongodb-native/commit/be19a2160d33d8e7473800fbcf6af1cd7f6eaeef))
28
+ * always clear cancelled wait queue members during processing ([3087d48](https://github.com/mongodb/node-mongodb-native/commit/3087d48c5de17dcd77d48b35af591a8f6780d145))
29
+ * always include `writeErrors` on a `BulkWriteError` instance ([40db47f](https://github.com/mongodb/node-mongodb-native/commit/40db47f5aac1e93a11e8568327e93c4c542e11da))
30
+ * assert update/replace atomic requirements in bulk operations ([31ae3c9](https://github.com/mongodb/node-mongodb-native/commit/31ae3c9978d6ea4f33c3ea4ccac9cd41841e31de))
31
+ * clarify handle wrong set name single topology ([21424eb](https://github.com/mongodb/node-mongodb-native/commit/21424ebb961db339be8fa74babaaeb3ada8e22c8))
32
+ * createCollection only uses listCollections in strict mode ([a8ffec4](https://github.com/mongodb/node-mongodb-native/commit/a8ffec4c0b4e2ef0ce4c3bcdadc0adeccd0a3544))
33
+ * db.command to not inherit options from parent ([c394284](https://github.com/mongodb/node-mongodb-native/commit/c39428421c94b4a1c5f41340e5b1a82724af95bd))
34
+ * don't create multiple rtt pingers if one already exists ([56723aa](https://github.com/mongodb/node-mongodb-native/commit/56723aa1c980894ededd97531ff023a603cf4271))
35
+ * don't immediately schedule monitoring after streaming failure ([188c23e](https://github.com/mongodb/node-mongodb-native/commit/188c23e0bb173a032df6bea4c7d2a916b808d9ad))
36
+ * don't reapply socket timeout when socket has `moreToCome` ([ca0f2b9](https://github.com/mongodb/node-mongodb-native/commit/ca0f2b9d3fc268187d112e3afbe7bc556273e100))
37
+ * don't try to calculate sMax if there are no viable servers ([4cb9b64](https://github.com/mongodb/node-mongodb-native/commit/4cb9b64bc3ff9aed8f26091cfe52acb152146898))
38
+ * ensure implicit sessions are ended consistently ([8c861f3](https://github.com/mongodb/node-mongodb-native/commit/8c861f3e6c743a65ee95c8036ee0c1b1bc8c427a))
39
+ * filter servers before applying reducers ([6f7d9bf](https://github.com/mongodb/node-mongodb-native/commit/6f7d9bf7f03108af3d190965a8b536ec2fb68a0b))
40
+ * hint should raise error on unacknowledged writes ([54aa19e](https://github.com/mongodb/node-mongodb-native/commit/54aa19ea10a18ee6fce93f7c7eb6562c9f4042a5))
41
+ * honor journal=true in connection string ([#2358](https://github.com/mongodb/node-mongodb-native/issues/2358)) ([4df4b7c](https://github.com/mongodb/node-mongodb-native/commit/4df4b7c3133925432954ce249c8bf8ae34674cb9))
42
+ * IPv6 is not supported when using dns service discovery ([19ec62f](https://github.com/mongodb/node-mongodb-native/commit/19ec62fad5912b5e1f615278a4c2fba153da5030))
43
+ * linting issue ([babf845](https://github.com/mongodb/node-mongodb-native/commit/babf84517675240c5ca39631c771e04ba9e248d7))
44
+ * MONGODB-AWS temporary credentials are added to authContext ([769a754](https://github.com/mongodb/node-mongodb-native/commit/769a75491ede69a6af8da8f2d6572c6c85e14a62))
45
+ * ReadPreference maxStalenessSeconds from options ([dfe7afa](https://github.com/mongodb/node-mongodb-native/commit/dfe7afaf646b2cde1751e728b52fa40d672beb55))
46
+ * reduce default keepalive time to align with Azure defaults ([72d8969](https://github.com/mongodb/node-mongodb-native/commit/72d896983ed70fd0f96dea3a37ff05a5d91a93ba))
47
+ * remove destructuring assignments for legacy node support ([d728a13](https://github.com/mongodb/node-mongodb-native/commit/d728a1330a37e847b69937b42e179c58b47038cb))
48
+ * silently ignore session with unacknowledged write ([a053f4e](https://github.com/mongodb/node-mongodb-native/commit/a053f4ea3f5ad1c8c8a581c449cf03dc252aeb06))
49
+ * **ChangeStream:** handle null changes ([14179a2](https://github.com/mongodb/node-mongodb-native/commit/14179a270ce4bfa62884ee53d46f4e35d28b6100))
50
+ * **ChangeStream:** make CursorNotFound error resumable ([9f0b7ab](https://github.com/mongodb/node-mongodb-native/commit/9f0b7ab65a5d443f411a61fa1a3dd6cfe42b8dce))
51
+ * **ChangeStream:** should resume from errors when iterating ([497952c](https://github.com/mongodb/node-mongodb-native/commit/497952cd577dc692dc2e0273028a74c818d31174))
52
+ * **ChangeStream:** whitelist resumable errors ([#2337](https://github.com/mongodb/node-mongodb-native/issues/2337)) ([a9d3965](https://github.com/mongodb/node-mongodb-native/commit/a9d39651e5a3d5e565a85d1eb503f56f07c4a1d3)), closes [#17](https://github.com/mongodb/node-mongodb-native/issues/17) [#18](https://github.com/mongodb/node-mongodb-native/issues/18)
53
+ * **create_indexes:** add missing `bucketSize` option to list of valid options ([66c76c3](https://github.com/mongodb/node-mongodb-native/commit/66c76c32f900499e147656e07b2df7bc5e0bb1b5))
54
+ * **GridFS:** emit error on bad options ([c71a4df](https://github.com/mongodb/node-mongodb-native/commit/c71a4dfdf1c4904321a2b50967b3379b13d774fb))
55
+ * remove check for NonResumableChangeStreamError label ([f3ac635](https://github.com/mongodb/node-mongodb-native/commit/f3ac635663717dd9eb00bf8d3f938a56c98bcafb))
56
+ * throw an error if `allowDiskUse` is used on MongoDB < 3.2 ([f95f697](https://github.com/mongodb/node-mongodb-native/commit/f95f697dde5ba1ae4c6a698ad29266dfd787a121))
57
+ * typo with setting error labels on error object ([89638bf](https://github.com/mongodb/node-mongodb-native/commit/89638bf925482bb54c3dd956ffd6f2830d088c6a))
58
+ * unordered bulk write should attempt to execute all batches ([d00a644](https://github.com/mongodb/node-mongodb-native/commit/d00a644e129ad9570a5727b7e259261204f259ae))
59
+ * use async interruptable interval for server monitoring ([068ae83](https://github.com/mongodb/node-mongodb-native/commit/068ae83291fc30f76b23ea1120e77ce71053e29d))
60
+ * writes within transactions are not retryable ([c13ec5c](https://github.com/mongodb/node-mongodb-native/commit/c13ec5c66623af164b688c79747eab8fe89b91d6))
61
+
62
+ ## [3.6.0-beta.0](https://github.com/mongodb/node-mongodb-native/compare/v3.5.5...v3.6.0-beta.0) (2020-04-14)
14
63
 
15
64
 
16
65
  ### Features
17
66
 
18
- * introduce an interruptable async interval timer ([9e12cd5](https://github.com/mongodb/node-mongodb-native/commit/9e12cd5))
67
+ * add MONGODB-AWS as a supported auth mechanism ([7f3cfba](https://github.com/mongodb/node-mongodb-native/commit/7f3cfbac15f537aa2ca9da145063f10c61390406))
68
+ * bump wire protocol version for 4.4 ([6d3f313](https://github.com/mongodb/node-mongodb-native/commit/6d3f313a9defd12489b621896439b3f9ec8cb1ae))
69
+ * deprecate `oplogReplay` for find commands ([24155e7](https://github.com/mongodb/node-mongodb-native/commit/24155e7905422460afc7e6abb120c596f40712c1))
70
+ * directConnection adds unify behavior for replica set discovery ([c5d60fc](https://github.com/mongodb/node-mongodb-native/commit/c5d60fc4619227697ef2102437fe5c8b111909d2))
71
+ * expand use of error labels for retryable writes ([c775a4a](https://github.com/mongodb/node-mongodb-native/commit/c775a4a1c53b8476eff6c9759b5647c9cbfa4e04))
72
+ * support `allowDiskUse` for find commands ([dbc0b37](https://github.com/mongodb/node-mongodb-native/commit/dbc0b3722516a128c253bf85366a3432756ff92a))
73
+ * support creating collections and indexes in transactions ([17e4c88](https://github.com/mongodb/node-mongodb-native/commit/17e4c88575b734d2d8ff94ca7f68b731a0bad326))
74
+ * support passing a hint to findOneAndReplace/findOneAndUpdate ([faee15b](https://github.com/mongodb/node-mongodb-native/commit/faee15b686b895b84fd0b52c1e69e0caec769732))
75
+ * support shorter SCRAM conversations ([6b9ff05](https://github.com/mongodb/node-mongodb-native/commit/6b9ff0561d14818bf07f4946ade04fc54683d0b9))
76
+ * use error labels for retryable writes in legacy topologies ([fefc165](https://github.com/mongodb/node-mongodb-native/commit/fefc1651a885ec28758271c9e3c36104b05bdb75))
19
77
 
20
78
 
79
+ ### Bug Fixes
21
80
 
22
- <a name="3.5.8"></a>
23
- ## [3.5.8](https://github.com/mongodb/node-mongodb-native/compare/v3.5.7...v3.5.8) (2020-05-28)
81
+ * **ChangeStream:** whitelist change stream resumable errors ([8a9c108](https://github.com/mongodb/node-mongodb-native/commit/8a9c1084430de9d6253ca9c61c9258c85835bb94)), closes [#17](https://github.com/mongodb/node-mongodb-native/issues/17) [#18](https://github.com/mongodb/node-mongodb-native/issues/18)
82
+ * always return empty array for selection on unknown topology ([af57b57](https://github.com/mongodb/node-mongodb-native/commit/af57b578dd603faa7b66983232de2bc7e417dae1))
83
+ * correctly use template string for connection string error message ([814e278](https://github.com/mongodb/node-mongodb-native/commit/814e27869d90a1dfa01118bb96ff1273e0cef323))
84
+ * don't depend on private node api for `Timeout` wrapper ([e6dc1f4](https://github.com/mongodb/node-mongodb-native/commit/e6dc1f48d62b68ba56b93359d7aa755c08985867))
85
+ * **sdam:** use ObjectId comparison to track maxElectionId ([db991d6](https://github.com/mongodb/node-mongodb-native/commit/db991d6916306d1fe08508d4c3e8f7a37d7fd21f))
86
+ * only consider MongoError subclasses for retryability ([265fe40](https://github.com/mongodb/node-mongodb-native/commit/265fe40cf29992764d1ab030a1ee4dca97cd7c7c))
87
+ * pass options into `commandSupportsReadConcern` ([e855c83](https://github.com/mongodb/node-mongodb-native/commit/e855c83d8b73f4ce57a11193a1e52461ab2cd4db))
88
+ * store name of collection for more informative error messages ([979d41e](https://github.com/mongodb/node-mongodb-native/commit/979d41e14f5acf69bac094b3863591ee8e01fd9c))
89
+ * support write concern provided as string in `fromOptions` ([637f428](https://github.com/mongodb/node-mongodb-native/commit/637f4288c1edb799267ccbce6d25a49304f6149c))
90
+ * use properly camel cased form of `mapReduce` for command ([c1ed2c1](https://github.com/mongodb/node-mongodb-native/commit/c1ed2c1ce4c6f2d40cd1c7b84ad672a90a09c83b))
24
91
 
92
+ <a name="3.6.0-beta.0"></a>
93
+ # [3.6.0-beta.0](https://github.com/mongodb/node-mongodb-native/compare/v3.5.5...v3.6.0-beta.0) (2020-04-14)
25
94
 
26
95
  ### Bug Fixes
27
96
 
28
- * always clear cancelled wait queue members during processing ([0394f9d](https://github.com/mongodb/node-mongodb-native/commit/0394f9d))
29
- * always include `writeErrors` on a `BulkWriteError` instance ([58b4f94](https://github.com/mongodb/node-mongodb-native/commit/58b4f94))
30
- * ensure implicit sessions are ended consistently ([5c6fda1](https://github.com/mongodb/node-mongodb-native/commit/5c6fda1))
31
- * filter servers before applying reducers ([4faf9f5](https://github.com/mongodb/node-mongodb-native/commit/4faf9f5))
32
- * unordered bulk write should attempt to execute all batches ([6cee96b](https://github.com/mongodb/node-mongodb-native/commit/6cee96b))
33
- * **ChangeStream:** should resume from errors when iterating ([5ecf18e](https://github.com/mongodb/node-mongodb-native/commit/5ecf18e))
34
- * 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))
35
- * **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)
97
+ * always return empty array for selection on unknown topology ([af57b57](https://github.com/mongodb/node-mongodb-native/commit/af57b57))
98
+ * always return empty array for selection on unknown topology ([f9e786a](https://github.com/mongodb/node-mongodb-native/commit/f9e786a))
99
+ * correctly use template string for connection string error message ([814e278](https://github.com/mongodb/node-mongodb-native/commit/814e278))
100
+ * createCollection only uses listCollections in strict mode ([d368f12](https://github.com/mongodb/node-mongodb-native/commit/d368f12))
101
+ * don't depend on private node api for `Timeout` wrapper ([e6dc1f4](https://github.com/mongodb/node-mongodb-native/commit/e6dc1f4))
102
+ * don't throw if `withTransaction()` callback rejects with a null reason ([153646c](https://github.com/mongodb/node-mongodb-native/commit/153646c))
103
+ * **cursor:** transforms should only be applied once to documents ([704f30a](https://github.com/mongodb/node-mongodb-native/commit/704f30a))
104
+ * only consider MongoError subclasses for retryability ([265fe40](https://github.com/mongodb/node-mongodb-native/commit/265fe40))
105
+ * **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)
106
+ * **sdam:** use ObjectId comparison to track maxElectionId ([db991d6](https://github.com/mongodb/node-mongodb-native/commit/db991d6))
107
+ * only mark server session dirty if the client session is alive ([611be8d](https://github.com/mongodb/node-mongodb-native/commit/611be8d))
108
+ * pass options into `commandSupportsReadConcern` ([e855c83](https://github.com/mongodb/node-mongodb-native/commit/e855c83))
109
+ * polyfill for util.promisify ([1c4cf6c](https://github.com/mongodb/node-mongodb-native/commit/1c4cf6c))
110
+ * single `readPreferenceTags` should be parsed as an array ([a50611b](https://github.com/mongodb/node-mongodb-native/commit/a50611b))
111
+ * store name of collection for more informative error messages ([979d41e](https://github.com/mongodb/node-mongodb-native/commit/979d41e))
112
+ * support write concern provided as string in `fromOptions` ([637f428](https://github.com/mongodb/node-mongodb-native/commit/637f428))
113
+ * use properly camel cased form of `mapReduce` for command ([c1ed2c1](https://github.com/mongodb/node-mongodb-native/commit/c1ed2c1))
114
+
115
+
116
+ ### Features
117
+
118
+ * add MONGODB-AWS as a supported auth mechanism ([7f3cfba](https://github.com/mongodb/node-mongodb-native/commit/7f3cfba))
119
+ * bump wire protocol version for 4.4 ([6d3f313](https://github.com/mongodb/node-mongodb-native/commit/6d3f313))
120
+ * deprecate `oplogReplay` for find commands ([24155e7](https://github.com/mongodb/node-mongodb-native/commit/24155e7))
121
+ * directConnection adds unify behavior for replica set discovery ([c5d60fc](https://github.com/mongodb/node-mongodb-native/commit/c5d60fc))
122
+ * expand use of error labels for retryable writes ([c775a4a](https://github.com/mongodb/node-mongodb-native/commit/c775a4a))
123
+ * support `allowDiskUse` for find commands ([dbc0b37](https://github.com/mongodb/node-mongodb-native/commit/dbc0b37))
124
+ * support creating collections and indexes in transactions ([17e4c88](https://github.com/mongodb/node-mongodb-native/commit/17e4c88))
125
+ * support passing a hint to findOneAndReplace/findOneAndUpdate ([faee15b](https://github.com/mongodb/node-mongodb-native/commit/faee15b))
126
+ * support shorter SCRAM conversations ([6b9ff05](https://github.com/mongodb/node-mongodb-native/commit/6b9ff05))
127
+ * use error labels for retryable writes in legacy topologies ([fefc165](https://github.com/mongodb/node-mongodb-native/commit/fefc165))
128
+
36
129
 
37
130
 
38
131
 
@@ -50,7 +143,6 @@ All notable changes to this project will be documented in this file. See [standa
50
143
  <a name="3.5.6"></a>
51
144
  ## [3.5.6](https://github.com/mongodb/node-mongodb-native/compare/v3.5.5...v3.5.6) (2020-04-14)
52
145
 
53
-
54
146
  ### Bug Fixes
55
147
 
56
148
  * 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() {
@@ -326,8 +325,8 @@ class ChangeStreamCursor extends Cursor {
326
325
 
327
326
  _initializeCursor(callback) {
328
327
  super._initializeCursor((err, result) => {
329
- if (err) {
330
- callback(err);
328
+ if (err || result == null) {
329
+ callback(err, result);
331
330
  return;
332
331
  }
333
332
 
@@ -483,6 +482,11 @@ function waitForTopologyConnected(topology, options, callback) {
483
482
  function processNewChange(changeStream, change, callback) {
484
483
  const cursor = changeStream.cursor;
485
484
 
485
+ // a null change means the cursor has been notified, implicitly closing the change stream
486
+ if (change == null) {
487
+ changeStream.closed = true;
488
+ }
489
+
486
490
  if (changeStream.closed) {
487
491
  if (callback) callback(new MongoError('ChangeStream is closed'));
488
492
  return;
@@ -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;
@@ -77,10 +78,14 @@ class Connection extends EventEmitter {
77
78
  stream.destroy();
78
79
  this.closed = true;
79
80
  this[kQueue].forEach(op =>
80
- op.cb(new MongoNetworkError(`connection ${this.id} to ${this.address} timed out`))
81
+ op.cb(
82
+ new MongoNetworkTimeoutError(`connection ${this.id} to ${this.address} timed out`, {
83
+ beforeHandshake: this[kIsMaster] == null
84
+ })
85
+ )
81
86
  );
82
- this[kQueue].clear();
83
87
 
88
+ this[kQueue].clear();
84
89
  this.emit('close');
85
90
  });
86
91
 
@@ -218,6 +223,7 @@ function messageHandler(conn) {
218
223
  }
219
224
 
220
225
  const operationDescription = conn[kQueue].get(message.responseTo);
226
+ const callback = operationDescription.cb;
221
227
 
222
228
  // SERVER-45775: For exhaust responses we should be able to use the same requestId to
223
229
  // track response, however the server currently synthetically produces remote requests
@@ -226,10 +232,7 @@ function messageHandler(conn) {
226
232
  if (message.moreToCome) {
227
233
  // requeue the callback for next synthetic request
228
234
  conn[kQueue].set(message.requestId, operationDescription);
229
- }
230
-
231
- const callback = operationDescription.cb;
232
- if (operationDescription.socketTimeoutOverride) {
235
+ } else if (operationDescription.socketTimeoutOverride) {
233
236
  conn[kStream].setTimeout(conn.socketTimeout);
234
237
  }
235
238