mongodb 3.5.10 → 3.6.1

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 (66) hide show
  1. package/HISTORY.md +38 -28
  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 +11 -6
  6. package/lib/collection.js +59 -81
  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 +124 -214
  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/error.js +82 -8
  20. package/lib/core/sdam/common.js +8 -0
  21. package/lib/core/sdam/monitor.js +240 -78
  22. package/lib/core/sdam/server.js +81 -15
  23. package/lib/core/sdam/server_description.js +37 -2
  24. package/lib/core/sdam/topology.js +41 -8
  25. package/lib/core/sdam/topology_description.js +21 -3
  26. package/lib/core/sessions.js +9 -16
  27. package/lib/core/topologies/mongos.js +18 -6
  28. package/lib/core/topologies/read_preference.js +15 -3
  29. package/lib/core/topologies/replset.js +4 -4
  30. package/lib/core/topologies/server.js +1 -1
  31. package/lib/core/topologies/shared.js +39 -16
  32. package/lib/core/uri_parser.js +41 -6
  33. package/lib/core/utils.js +30 -0
  34. package/lib/core/wireprotocol/command.js +1 -4
  35. package/lib/core/wireprotocol/constants.js +2 -2
  36. package/lib/core/wireprotocol/query.js +4 -0
  37. package/lib/cursor.js +0 -1
  38. package/lib/db.js +6 -5
  39. package/lib/error.js +6 -1
  40. package/lib/gridfs-stream/download.js +13 -2
  41. package/lib/mongo_client.js +6 -4
  42. package/lib/operations/collection_ops.js +0 -20
  43. package/lib/operations/command_v2.js +1 -1
  44. package/lib/operations/common_functions.js +3 -0
  45. package/lib/operations/connect.js +11 -14
  46. package/lib/operations/create_collection.js +37 -52
  47. package/lib/operations/create_indexes.js +111 -35
  48. package/lib/operations/find.js +7 -1
  49. package/lib/operations/find_and_modify.js +17 -0
  50. package/lib/operations/find_one_and_delete.js +5 -0
  51. package/lib/operations/find_one_and_replace.js +13 -0
  52. package/lib/operations/find_one_and_update.js +13 -0
  53. package/lib/operations/map_reduce.js +1 -1
  54. package/lib/operations/re_index.js +22 -17
  55. package/lib/operations/replace_one.js +11 -4
  56. package/lib/operations/update_many.js +5 -0
  57. package/lib/operations/update_one.js +5 -0
  58. package/lib/operations/validate_collection.js +1 -2
  59. package/lib/topologies/mongos.js +1 -1
  60. package/lib/topologies/replset.js +1 -1
  61. package/lib/topologies/server.js +1 -1
  62. package/lib/utils.js +18 -1
  63. package/lib/write_concern.js +10 -0
  64. package/package.json +4 -1
  65. package/lib/core/auth/sspi.js +0 -131
  66. package/lib/operations/create_index.js +0 -92
package/HISTORY.md CHANGED
@@ -1,49 +1,60 @@
1
- # Changelog
1
+ # Change Log
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
- ### [3.5.10](https://github.com/mongodb/node-mongodb-native/compare/v3.5.9...v3.5.10) (2020-07-30)
5
+ <a name="3.6.1"></a>
6
+ ## [3.6.1](https://github.com/mongodb/node-mongodb-native/compare/v3.6.0...v3.6.1) (2020-09-02)
6
7
 
7
8
 
8
9
  ### Bug Fixes
9
10
 
10
- * db.command to not inherit options from parent ([f7a50e2](https://github.com/mongodb/node-mongodb-native/commit/f7a50e2f43375cc411d6f521e3b103c96ceca51a))
11
- * ipv6 is not supported when using dns service discovery ([a1be593](https://github.com/mongodb/node-mongodb-native/commit/a1be59315c3dc65a04d3f83bb75fff2f1b9c16ef))
12
- * ReadPreference maxStalenessSeconds from options ([72a743d](https://github.com/mongodb/node-mongodb-native/commit/72a743d536181867f770a88ea9cd68d30b3f97fd))
13
- * silently ignore session with unacknowledged write ([8f1ea7b](https://github.com/mongodb/node-mongodb-native/commit/8f1ea7b69678c243a729267109ac3e50387914f8))
14
- * **ChangeStream:** handle null changes ([306b5b3](https://github.com/mongodb/node-mongodb-native/commit/306b5b3f7103f91c6c07c08f95375876093ad897))
11
+ * add host/port to cmap connection ([06a2444](https://github.com/mongodb/node-mongodb-native/commit/06a2444))
12
+ * update full list of index options ([0af3191](https://github.com/mongodb/node-mongodb-native/commit/0af3191))
15
13
 
16
- <a name="3.5.9"></a>
17
- ## [3.5.9](https://github.com/mongodb/node-mongodb-native/compare/v3.5.8...v3.5.9) (2020-06-12)
18
14
 
15
+ ### Features
19
16
 
20
- ### Bug Fixes
21
-
22
- * don't try to calculate sMax if there are no viable servers ([be51347](https://github.com/mongodb/node-mongodb-native/commit/be51347))
23
- * use async interruptable interval for server monitoring ([1f855a4](https://github.com/mongodb/node-mongodb-native/commit/1f855a4))
24
- * use duration of handshake if no previous roundTripTime exists ([ddfa41b](https://github.com/mongodb/node-mongodb-native/commit/ddfa41b))
17
+ * **db:** deprecate createCollection strict mode ([4cc6bcc](https://github.com/mongodb/node-mongodb-native/commit/4cc6bcc))
25
18
 
26
19
 
27
- ### Features
28
20
 
29
- * introduce an interruptable async interval timer ([9e12cd5](https://github.com/mongodb/node-mongodb-native/commit/9e12cd5))
21
+ <a name="3.6.0-beta.0"></a>
22
+ # [3.6.0-beta.0](https://github.com/mongodb/node-mongodb-native/compare/v3.5.5...v3.6.0-beta.0) (2020-04-14)
30
23
 
24
+ ### Bug Fixes
31
25
 
26
+ * always return empty array for selection on unknown topology ([af57b57](https://github.com/mongodb/node-mongodb-native/commit/af57b57))
27
+ * always return empty array for selection on unknown topology ([f9e786a](https://github.com/mongodb/node-mongodb-native/commit/f9e786a))
28
+ * correctly use template string for connection string error message ([814e278](https://github.com/mongodb/node-mongodb-native/commit/814e278))
29
+ * createCollection only uses listCollections in strict mode ([d368f12](https://github.com/mongodb/node-mongodb-native/commit/d368f12))
30
+ * don't depend on private node api for `Timeout` wrapper ([e6dc1f4](https://github.com/mongodb/node-mongodb-native/commit/e6dc1f4))
31
+ * don't throw if `withTransaction()` callback rejects with a null reason ([153646c](https://github.com/mongodb/node-mongodb-native/commit/153646c))
32
+ * **cursor:** transforms should only be applied once to documents ([704f30a](https://github.com/mongodb/node-mongodb-native/commit/704f30a))
33
+ * only consider MongoError subclasses for retryability ([265fe40](https://github.com/mongodb/node-mongodb-native/commit/265fe40))
34
+ * **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)
35
+ * **sdam:** use ObjectId comparison to track maxElectionId ([db991d6](https://github.com/mongodb/node-mongodb-native/commit/db991d6))
36
+ * only mark server session dirty if the client session is alive ([611be8d](https://github.com/mongodb/node-mongodb-native/commit/611be8d))
37
+ * pass options into `commandSupportsReadConcern` ([e855c83](https://github.com/mongodb/node-mongodb-native/commit/e855c83))
38
+ * polyfill for util.promisify ([1c4cf6c](https://github.com/mongodb/node-mongodb-native/commit/1c4cf6c))
39
+ * single `readPreferenceTags` should be parsed as an array ([a50611b](https://github.com/mongodb/node-mongodb-native/commit/a50611b))
40
+ * store name of collection for more informative error messages ([979d41e](https://github.com/mongodb/node-mongodb-native/commit/979d41e))
41
+ * support write concern provided as string in `fromOptions` ([637f428](https://github.com/mongodb/node-mongodb-native/commit/637f428))
42
+ * use properly camel cased form of `mapReduce` for command ([c1ed2c1](https://github.com/mongodb/node-mongodb-native/commit/c1ed2c1))
32
43
 
33
- <a name="3.5.8"></a>
34
- ## [3.5.8](https://github.com/mongodb/node-mongodb-native/compare/v3.5.7...v3.5.8) (2020-05-28)
35
44
 
45
+ ### Features
36
46
 
37
- ### Bug Fixes
47
+ * add MONGODB-AWS as a supported auth mechanism ([7f3cfba](https://github.com/mongodb/node-mongodb-native/commit/7f3cfba))
48
+ * bump wire protocol version for 4.4 ([6d3f313](https://github.com/mongodb/node-mongodb-native/commit/6d3f313))
49
+ * deprecate `oplogReplay` for find commands ([24155e7](https://github.com/mongodb/node-mongodb-native/commit/24155e7))
50
+ * directConnection adds unify behavior for replica set discovery ([c5d60fc](https://github.com/mongodb/node-mongodb-native/commit/c5d60fc))
51
+ * expand use of error labels for retryable writes ([c775a4a](https://github.com/mongodb/node-mongodb-native/commit/c775a4a))
52
+ * support `allowDiskUse` for find commands ([dbc0b37](https://github.com/mongodb/node-mongodb-native/commit/dbc0b37))
53
+ * support creating collections and indexes in transactions ([17e4c88](https://github.com/mongodb/node-mongodb-native/commit/17e4c88))
54
+ * support passing a hint to findOneAndReplace/findOneAndUpdate ([faee15b](https://github.com/mongodb/node-mongodb-native/commit/faee15b))
55
+ * support shorter SCRAM conversations ([6b9ff05](https://github.com/mongodb/node-mongodb-native/commit/6b9ff05))
56
+ * use error labels for retryable writes in legacy topologies ([fefc165](https://github.com/mongodb/node-mongodb-native/commit/fefc165))
38
57
 
39
- * always clear cancelled wait queue members during processing ([0394f9d](https://github.com/mongodb/node-mongodb-native/commit/0394f9d))
40
- * always include `writeErrors` on a `BulkWriteError` instance ([58b4f94](https://github.com/mongodb/node-mongodb-native/commit/58b4f94))
41
- * ensure implicit sessions are ended consistently ([5c6fda1](https://github.com/mongodb/node-mongodb-native/commit/5c6fda1))
42
- * filter servers before applying reducers ([4faf9f5](https://github.com/mongodb/node-mongodb-native/commit/4faf9f5))
43
- * unordered bulk write should attempt to execute all batches ([6cee96b](https://github.com/mongodb/node-mongodb-native/commit/6cee96b))
44
- * **ChangeStream:** should resume from errors when iterating ([5ecf18e](https://github.com/mongodb/node-mongodb-native/commit/5ecf18e))
45
- * 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))
46
- * **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)
47
58
 
48
59
 
49
60
 
@@ -61,7 +72,6 @@ All notable changes to this project will be documented in this file. See [standa
61
72
  <a name="3.5.6"></a>
62
73
  ## [3.5.6](https://github.com/mongodb/node-mongodb-native/compare/v3.5.5...v3.5.6) (2020-04-14)
63
74
 
64
-
65
75
  ### Bug Fixes
66
76
 
67
77
  * 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;
@@ -32,6 +33,8 @@ class Connection extends EventEmitter {
32
33
  this.address = streamIdentifier(stream);
33
34
  this.bson = options.bson;
34
35
  this.socketTimeout = typeof options.socketTimeout === 'number' ? options.socketTimeout : 360000;
36
+ this.host = options.host || 'localhost';
37
+ this.port = options.port || 27017;
35
38
  this.monitorCommands =
36
39
  typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false;
37
40
  this.closed = false;
@@ -77,10 +80,14 @@ class Connection extends EventEmitter {
77
80
  stream.destroy();
78
81
  this.closed = true;
79
82
  this[kQueue].forEach(op =>
80
- 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
+ )
81
88
  );
82
- this[kQueue].clear();
83
89
 
90
+ this[kQueue].clear();
84
91
  this.emit('close');
85
92
  });
86
93
 
@@ -218,6 +225,7 @@ function messageHandler(conn) {
218
225
  }
219
226
 
220
227
  const operationDescription = conn[kQueue].get(message.responseTo);
228
+ const callback = operationDescription.cb;
221
229
 
222
230
  // SERVER-45775: For exhaust responses we should be able to use the same requestId to
223
231
  // track response, however the server currently synthetically produces remote requests
@@ -226,10 +234,7 @@ function messageHandler(conn) {
226
234
  if (message.moreToCome) {
227
235
  // requeue the callback for next synthetic request
228
236
  conn[kQueue].set(message.requestId, operationDescription);
229
- }
230
-
231
- const callback = operationDescription.cb;
232
- if (operationDescription.socketTimeoutOverride) {
237
+ } else if (operationDescription.socketTimeoutOverride) {
233
238
  conn[kStream].setTimeout(conn.socketTimeout);
234
239
  }
235
240
 
package/lib/collection.js CHANGED
@@ -5,7 +5,6 @@ const deprecateOptions = require('./utils').deprecateOptions;
5
5
  const checkCollectionName = require('./utils').checkCollectionName;
6
6
  const ObjectID = require('./core').BSON.ObjectID;
7
7
  const MongoError = require('./core').MongoError;
8
- const toError = require('./utils').toError;
9
8
  const normalizeHintField = require('./utils').normalizeHintField;
10
9
  const decorateCommand = require('./utils').decorateCommand;
11
10
  const decorateWithCollation = require('./utils').decorateWithCollation;
@@ -23,7 +22,6 @@ const AggregationCursor = require('./aggregation_cursor');
23
22
  const CommandCursor = require('./command_cursor');
24
23
 
25
24
  // Operations
26
- const checkForAtomicOperators = require('./operations/collection_ops').checkForAtomicOperators;
27
25
  const ensureIndex = require('./operations/collection_ops').ensureIndex;
28
26
  const group = require('./operations/collection_ops').group;
29
27
  const parallelCollectionScan = require('./operations/collection_ops').parallelCollectionScan;
@@ -34,7 +32,6 @@ const updateDocuments = require('./operations/common_functions').updateDocuments
34
32
  const AggregateOperation = require('./operations/aggregate');
35
33
  const BulkWriteOperation = require('./operations/bulk_write');
36
34
  const CountDocumentsOperation = require('./operations/count_documents');
37
- const CreateIndexOperation = require('./operations/create_index');
38
35
  const CreateIndexesOperation = require('./operations/create_indexes');
39
36
  const DeleteManyOperation = require('./operations/delete_many');
40
37
  const DeleteOneOperation = require('./operations/delete_one');
@@ -277,7 +274,7 @@ Object.defineProperty(Collection.prototype, 'hint', {
277
274
  }
278
275
  });
279
276
 
280
- const DEPRECATED_FIND_OPTIONS = ['maxScan', 'fields', 'snapshot'];
277
+ const DEPRECATED_FIND_OPTIONS = ['maxScan', 'fields', 'snapshot', 'oplogReplay'];
281
278
 
282
279
  /**
283
280
  * Creates a cursor for a query that can be used to iterate over results from MongoDB
@@ -312,6 +309,7 @@ const DEPRECATED_FIND_OPTIONS = ['maxScan', 'fields', 'snapshot'];
312
309
  * @param {number} [options.maxAwaitTimeMS] The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. Requires `tailable` and `awaitData` to be true
313
310
  * @param {boolean} [options.noCursorTimeout] The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that.
314
311
  * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
312
+ * @param {boolean} [options.allowDiskUse] Enables writing to temporary files on the server.
315
313
  * @param {ClientSession} [options.session] optional session to use for this operation
316
314
  * @throws {MongoError}
317
315
  * @return {Cursor}
@@ -421,6 +419,10 @@ Collection.prototype.find = deprecateOptions(
421
419
  query: selector
422
420
  };
423
421
 
422
+ if (typeof options.allowDiskUse === 'boolean') {
423
+ findCommand.allowDiskUse = options.allowDiskUse;
424
+ }
425
+
424
426
  // Ensure we use the right await data option
425
427
  if (typeof newOptions.awaitdata === 'boolean') {
426
428
  newOptions.awaitData = newOptions.awaitdata;
@@ -743,14 +745,6 @@ Collection.prototype.insert = deprecate(function(docs, options, callback) {
743
745
  */
744
746
  Collection.prototype.updateOne = function(filter, update, options, callback) {
745
747
  if (typeof options === 'function') (callback = options), (options = {});
746
- options = options || {};
747
-
748
- const err = checkForAtomicOperators(update);
749
- if (err) {
750
- if (typeof callback === 'function') return callback(err);
751
- return this.s.promiseLibrary.reject(err);
752
- }
753
-
754
748
  options = Object.assign({}, options);
755
749
 
756
750
  // Add ignoreUndefined
@@ -759,9 +753,11 @@ Collection.prototype.updateOne = function(filter, update, options, callback) {
759
753
  options.ignoreUndefined = this.s.options.ignoreUndefined;
760
754
  }
761
755
 
762
- const updateOneOperation = new UpdateOneOperation(this, filter, update, options);
763
-
764
- return executeOperation(this.s.topology, updateOneOperation, callback);
756
+ return executeOperation(
757
+ this.s.topology,
758
+ new UpdateOneOperation(this, filter, update, options),
759
+ callback
760
+ );
765
761
  };
766
762
 
767
763
  /**
@@ -794,9 +790,11 @@ Collection.prototype.replaceOne = function(filter, doc, options, callback) {
794
790
  options.ignoreUndefined = this.s.options.ignoreUndefined;
795
791
  }
796
792
 
797
- const replaceOneOperation = new ReplaceOneOperation(this, filter, doc, options);
798
-
799
- return executeOperation(this.s.topology, replaceOneOperation, callback);
793
+ return executeOperation(
794
+ this.s.topology,
795
+ new ReplaceOneOperation(this, filter, doc, options),
796
+ callback
797
+ );
800
798
  };
801
799
 
802
800
  /**
@@ -822,14 +820,6 @@ Collection.prototype.replaceOne = function(filter, doc, options, callback) {
822
820
  */
823
821
  Collection.prototype.updateMany = function(filter, update, options, callback) {
824
822
  if (typeof options === 'function') (callback = options), (options = {});
825
- options = options || {};
826
-
827
- const err = checkForAtomicOperators(update);
828
- if (err) {
829
- if (typeof callback === 'function') return callback(err);
830
- return this.s.promiseLibrary.reject(err);
831
- }
832
-
833
823
  options = Object.assign({}, options);
834
824
 
835
825
  // Add ignoreUndefined
@@ -838,9 +828,11 @@ Collection.prototype.updateMany = function(filter, update, options, callback) {
838
828
  options.ignoreUndefined = this.s.options.ignoreUndefined;
839
829
  }
840
830
 
841
- const updateManyOperation = new UpdateManyOperation(this, filter, update, options);
842
-
843
- return executeOperation(this.s.topology, updateManyOperation, callback);
831
+ return executeOperation(
832
+ this.s.topology,
833
+ new UpdateManyOperation(this, filter, update, options),
834
+ callback
835
+ );
844
836
  };
845
837
 
846
838
  /**
@@ -912,6 +904,7 @@ Collection.prototype.update = deprecate(function(selector, update, options, call
912
904
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
913
905
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
914
906
  * @param {ClientSession} [options.session] optional session to use for this operation
907
+ * @param {string|object} [options.hint] optional index hint for optimizing the filter query
915
908
  * @param {Collection~deleteWriteOpCallback} [callback] The command result callback
916
909
  * @return {Promise} returns Promise if no callback passed
917
910
  */
@@ -945,6 +938,7 @@ Collection.prototype.removeOne = Collection.prototype.deleteOne;
945
938
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
946
939
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
947
940
  * @param {ClientSession} [options.session] optional session to use for this operation
941
+ * @param {string|object} [options.hint] optional index hint for optimizing the filter query
948
942
  * @param {Collection~deleteWriteOpCallback} [callback] The command result callback
949
943
  * @return {Promise} returns Promise if no callback passed
950
944
  */
@@ -1205,6 +1199,7 @@ Collection.prototype.isCapped = function(options, callback) {
1205
1199
  * @param {object} [options.partialFilterExpression] Creates a partial index based on the given filter object (MongoDB 3.2 or higher)
1206
1200
  * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
1207
1201
  * @param {ClientSession} [options.session] optional session to use for this operation
1202
+ * @param {(number|string)} [options.commitQuorum] (MongoDB 4.4. or higher) Specifies how many data-bearing members of a replica set, including the primary, must complete the index builds successfully before the primary marks the indexes as ready. This option accepts the same values for the "w" field in a write concern plus "votingMembers", which indicates all voting data-bearing nodes.
1208
1203
  * @param {Collection~resultCallback} [callback] The command result callback
1209
1204
  * @return {Promise} returns Promise if no callback passed
1210
1205
  * @example
@@ -1231,14 +1226,14 @@ Collection.prototype.createIndex = function(fieldOrSpec, options, callback) {
1231
1226
  if (typeof options === 'function') (callback = options), (options = {});
1232
1227
  options = options || {};
1233
1228
 
1234
- const createIndexOperation = new CreateIndexOperation(
1235
- this.s.db,
1229
+ const createIndexesOperation = new CreateIndexesOperation(
1230
+ this,
1236
1231
  this.collectionName,
1237
1232
  fieldOrSpec,
1238
1233
  options
1239
1234
  );
1240
1235
 
1241
- return executeOperation(this.s.topology, createIndexOperation, callback);
1236
+ return executeOperation(this.s.topology, createIndexesOperation, callback);
1242
1237
  };
1243
1238
 
1244
1239
  /**
@@ -1259,6 +1254,7 @@ Collection.prototype.createIndex = function(fieldOrSpec, options, callback) {
1259
1254
  * @param {Collection~IndexDefinition[]} indexSpecs An array of index specifications to be created
1260
1255
  * @param {Object} [options] Optional settings
1261
1256
  * @param {ClientSession} [options.session] optional session to use for this operation
1257
+ * @param {(number|string)} [options.commitQuorum] (MongoDB 4.4. or higher) Specifies how many data-bearing members of a replica set, including the primary, must complete the index builds successfully before the primary marks the indexes as ready. This option accepts the same values for the "w" field in a write concern plus "votingMembers", which indicates all voting data-bearing nodes.
1262
1258
  * @param {Collection~resultCallback} [callback] The command result callback
1263
1259
  * @return {Promise} returns Promise if no callback passed
1264
1260
  * @example
@@ -1283,9 +1279,15 @@ Collection.prototype.createIndexes = function(indexSpecs, options, callback) {
1283
1279
  if (typeof options === 'function') (callback = options), (options = {});
1284
1280
 
1285
1281
  options = options ? Object.assign({}, options) : {};
1282
+
1286
1283
  if (typeof options.maxTimeMS !== 'number') delete options.maxTimeMS;
1287
1284
 
1288
- const createIndexesOperation = new CreateIndexesOperation(this, indexSpecs, options);
1285
+ const createIndexesOperation = new CreateIndexesOperation(
1286
+ this,
1287
+ this.collectionName,
1288
+ indexSpecs,
1289
+ options
1290
+ );
1289
1291
 
1290
1292
  return executeOperation(this.s.topology, createIndexesOperation, callback);
1291
1293
  };
@@ -1352,19 +1354,20 @@ Collection.prototype.dropAllIndexes = deprecate(
1352
1354
  * Reindex all indexes on the collection
1353
1355
  * Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
1354
1356
  * @method
1357
+ * @deprecated use db.command instead
1355
1358
  * @param {Object} [options] Optional settings
1356
1359
  * @param {ClientSession} [options.session] optional session to use for this operation
1357
1360
  * @param {Collection~resultCallback} [callback] The command result callback
1358
1361
  * @return {Promise} returns Promise if no callback passed
1359
1362
  */
1360
- Collection.prototype.reIndex = function(options, callback) {
1363
+ Collection.prototype.reIndex = deprecate(function(options, callback) {
1361
1364
  if (typeof options === 'function') (callback = options), (options = {});
1362
1365
  options = options || {};
1363
1366
 
1364
1367
  const reIndexOperation = new ReIndexOperation(this, options);
1365
1368
 
1366
1369
  return executeOperation(this.s.topology, reIndexOperation, callback);
1367
- };
1370
+ }, 'collection.reIndex is deprecated. Use db.command instead.');
1368
1371
 
1369
1372
  /**
1370
1373
  * Get the list of all indexes information for the collection.
@@ -1664,13 +1667,11 @@ Collection.prototype.findOneAndDelete = function(filter, options, callback) {
1664
1667
  if (typeof options === 'function') (callback = options), (options = {});
1665
1668
  options = options || {};
1666
1669
 
1667
- // Basic validation
1668
- if (filter == null || typeof filter !== 'object')
1669
- throw toError('filter parameter must be an object');
1670
-
1671
- const findOneAndDeleteOperation = new FindOneAndDeleteOperation(this, filter, options);
1672
-
1673
- return executeOperation(this.s.topology, findOneAndDeleteOperation, callback);
1670
+ return executeOperation(
1671
+ this.s.topology,
1672
+ new FindOneAndDeleteOperation(this, filter, options),
1673
+ callback
1674
+ );
1674
1675
  };
1675
1676
 
1676
1677
  /**
@@ -1682,6 +1683,7 @@ Collection.prototype.findOneAndDelete = function(filter, options, callback) {
1682
1683
  * @param {object} [options] Optional settings.
1683
1684
  * @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
1684
1685
  * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
1686
+ * @param {string|object} [options.hint] An optional index to use for this operation
1685
1687
  * @param {number} [options.maxTimeMS] The maximum amount of time to allow the query to run.
1686
1688
  * @param {object} [options.projection] Limits the fields to return for all matching documents.
1687
1689
  * @param {object} [options.sort] Determines which document the operation modifies if the query selects multiple documents.
@@ -1698,27 +1700,11 @@ Collection.prototype.findOneAndReplace = function(filter, replacement, options,
1698
1700
  if (typeof options === 'function') (callback = options), (options = {});
1699
1701
  options = options || {};
1700
1702
 
1701
- // Basic validation
1702
- if (filter == null || typeof filter !== 'object')
1703
- throw toError('filter parameter must be an object');
1704
- if (replacement == null || typeof replacement !== 'object')
1705
- throw toError('replacement parameter must be an object');
1706
-
1707
- // Check that there are no atomic operators
1708
- const keys = Object.keys(replacement);
1709
-
1710
- if (keys[0] && keys[0][0] === '$') {
1711
- throw toError('The replacement document must not contain atomic operators.');
1712
- }
1713
-
1714
- const findOneAndReplaceOperation = new FindOneAndReplaceOperation(
1715
- this,
1716
- filter,
1717
- replacement,
1718
- options
1703
+ return executeOperation(
1704
+ this.s.topology,
1705
+ new FindOneAndReplaceOperation(this, filter, replacement, options),
1706
+ callback
1719
1707
  );
1720
-
1721
- return executeOperation(this.s.topology, findOneAndReplaceOperation, callback);
1722
1708
  };
1723
1709
 
1724
1710
  /**
@@ -1731,6 +1717,7 @@ Collection.prototype.findOneAndReplace = function(filter, replacement, options,
1731
1717
  * @param {Array} [options.arrayFilters] optional list of array filters referenced in filtered positional operators
1732
1718
  * @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
1733
1719
  * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
1720
+ * @param {string|object} [options.hint] An optional index to use for this operation
1734
1721
  * @param {number} [options.maxTimeMS] The maximum amount of time to allow the query to run.
1735
1722
  * @param {object} [options.projection] Limits the fields to return for all matching documents.
1736
1723
  * @param {object} [options.sort] Determines which document the operation modifies if the query selects multiple documents.
@@ -1739,7 +1726,7 @@ Collection.prototype.findOneAndReplace = function(filter, replacement, options,
1739
1726
  * @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
1740
1727
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
1741
1728
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
1742
- * @param {ClientSession} [options.session] optional session to use for this operation
1729
+ * @param {ClientSession} [options.session] An ptional session to use for this operation
1743
1730
  * @param {Collection~findAndModifyCallback} [callback] The collection result callback
1744
1731
  * @return {Promise<Collection~findAndModifyWriteOpResultObject>} returns Promise if no callback passed
1745
1732
  */
@@ -1747,21 +1734,11 @@ Collection.prototype.findOneAndUpdate = function(filter, update, options, callba
1747
1734
  if (typeof options === 'function') (callback = options), (options = {});
1748
1735
  options = options || {};
1749
1736
 
1750
- // Basic validation
1751
- if (filter == null || typeof filter !== 'object')
1752
- throw toError('filter parameter must be an object');
1753
- if (update == null || typeof update !== 'object')
1754
- throw toError('update parameter must be an object');
1755
-
1756
- const err = checkForAtomicOperators(update);
1757
- if (err) {
1758
- if (typeof callback === 'function') return callback(err);
1759
- return this.s.promiseLibrary.reject(err);
1760
- }
1761
-
1762
- const findOneAndUpdateOperation = new FindOneAndUpdateOperation(this, filter, update, options);
1763
-
1764
- return executeOperation(this.s.topology, findOneAndUpdateOperation, callback);
1737
+ return executeOperation(
1738
+ this.s.topology,
1739
+ new FindOneAndUpdateOperation(this, filter, update, options),
1740
+ callback
1741
+ );
1765
1742
  };
1766
1743
 
1767
1744
  /**
@@ -1863,7 +1840,7 @@ Collection.prototype.findAndRemove = deprecate(function(query, sort, options, ca
1863
1840
  * @param {boolean} [options.promoteLongs=true] Promotes Long values to number if they fit inside the 53 bits resolution.
1864
1841
  * @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types.
1865
1842
  * @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers.
1866
- * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
1843
+ * @param {object} [options.collation] Specify collation settings for operation. See {@link https://docs.mongodb.com/manual/reference/command/aggregate|aggregation documentation}.
1867
1844
  * @param {string} [options.comment] Add a comment to an aggregation command
1868
1845
  * @param {string|object} [options.hint] Add an index selection hint to an aggregation command
1869
1846
  * @param {ClientSession} [options.session] optional session to use for this operation
@@ -2008,8 +1985,9 @@ Collection.prototype.parallelCollectionScan = deprecate(function(options, callba
2008
1985
  * @param {ClientSession} [options.session] optional session to use for this operation
2009
1986
  * @param {Collection~resultCallback} [callback] The command result callback
2010
1987
  * @return {Promise} returns Promise if no callback passed
1988
+ * @deprecated See {@link https://docs.mongodb.com/manual/geospatial-queries/|geospatial queries docs} for current geospatial support
2011
1989
  */
2012
- Collection.prototype.geoHaystackSearch = function(x, y, options, callback) {
1990
+ Collection.prototype.geoHaystackSearch = deprecate(function(x, y, options, callback) {
2013
1991
  const args = Array.prototype.slice.call(arguments, 2);
2014
1992
  callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
2015
1993
  options = args.length ? args.shift() || {} : {};
@@ -2017,7 +1995,7 @@ Collection.prototype.geoHaystackSearch = function(x, y, options, callback) {
2017
1995
  const geoHaystackSearchOperation = new GeoHaystackSearchOperation(this, x, y, options);
2018
1996
 
2019
1997
  return executeOperation(this.s.topology, geoHaystackSearchOperation, callback);
2020
- };
1998
+ }, 'geoHaystackSearch is deprecated, and will be removed in a future version.');
2021
1999
 
2022
2000
  /**
2023
2001
  * Run a group command across a collection