mongodb 3.3.1 → 3.3.4

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 (41) hide show
  1. package/HISTORY.md +82 -0
  2. package/lib/aggregation_cursor.js +1 -1
  3. package/lib/bulk/common.js +166 -73
  4. package/lib/bulk/ordered.js +1 -1
  5. package/lib/bulk/unordered.js +1 -0
  6. package/lib/change_stream.js +2 -3
  7. package/lib/collection.js +70 -15
  8. package/lib/command_cursor.js +1 -1
  9. package/lib/core/connection/connect.js +20 -5
  10. package/lib/core/connection/connection.js +7 -3
  11. package/lib/core/connection/msg.js +3 -2
  12. package/lib/core/connection/pool.js +192 -206
  13. package/lib/core/cursor.js +1 -1
  14. package/lib/core/error.js +6 -1
  15. package/lib/core/sdam/monitoring.js +8 -1
  16. package/lib/core/sdam/server.js +90 -34
  17. package/lib/core/sdam/server_description.js +29 -0
  18. package/lib/core/sdam/topology.js +200 -91
  19. package/lib/core/sdam/topology_description.js +5 -3
  20. package/lib/core/topologies/mongos.js +72 -24
  21. package/lib/core/topologies/replset.js +34 -15
  22. package/lib/core/topologies/replset_state.js +5 -5
  23. package/lib/core/topologies/server.js +13 -12
  24. package/lib/core/topologies/shared.js +11 -15
  25. package/lib/core/uri_parser.js +8 -2
  26. package/lib/core/utils.js +40 -2
  27. package/lib/cursor.js +1 -1
  28. package/lib/db.js +3 -3
  29. package/lib/gridfs-stream/download.js +12 -5
  30. package/lib/gridfs-stream/index.js +1 -1
  31. package/lib/mongo_client.js +3 -3
  32. package/lib/operations/close.js +6 -2
  33. package/lib/operations/common_functions.js +4 -0
  34. package/lib/operations/connect.js +16 -13
  35. package/lib/operations/execute_operation.js +28 -12
  36. package/lib/operations/replace_one.js +1 -1
  37. package/lib/topologies/mongos.js +1 -1
  38. package/lib/topologies/replset.js +1 -1
  39. package/lib/topologies/server.js +1 -1
  40. package/lib/topologies/topology_base.js +4 -5
  41. package/package.json +11 -5
package/HISTORY.md CHANGED
@@ -2,6 +2,88 @@
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.3.4"></a>
6
+ ## [3.3.4](https://github.com/mongodb/node-mongodb-native/compare/v3.3.3...v3.3.4) (2019-11-11)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **close:** the unified topology emits a close event on close now ([ee0db01](https://github.com/mongodb/node-mongodb-native/commit/ee0db01))
12
+ * **connect:** prevent multiple callbacks in error scenarios ([5f6a787](https://github.com/mongodb/node-mongodb-native/commit/5f6a787))
13
+ * **monitoring:** incorrect states used to determine rescheduling ([ec1e04c](https://github.com/mongodb/node-mongodb-native/commit/ec1e04c))
14
+ * **pool:** don't reset a pool if we'not already connected ([32316e4](https://github.com/mongodb/node-mongodb-native/commit/32316e4))
15
+ * **pool:** only transition to `DISCONNECTED` if reconnect enabled ([43d461e](https://github.com/mongodb/node-mongodb-native/commit/43d461e))
16
+ * **replset:** don't leak servers failing to connect ([f209160](https://github.com/mongodb/node-mongodb-native/commit/f209160))
17
+ * **replset:** use correct `topologyId` for event emission ([19549ff](https://github.com/mongodb/node-mongodb-native/commit/19549ff))
18
+ * **sdam:** `minHeartbeatIntervalMS` => `minHeartbeatFrequencyMS` ([af9fb45](https://github.com/mongodb/node-mongodb-native/commit/af9fb45))
19
+ * **sdam:** don't emit `close` every time a child server closes ([818055a](https://github.com/mongodb/node-mongodb-native/commit/818055a))
20
+ * **sdam:** don't lose servers when they fail monitoring ([8a534bb](https://github.com/mongodb/node-mongodb-native/commit/8a534bb))
21
+ * **sdam:** don't remove unknown servers in topology updates ([1147ebf](https://github.com/mongodb/node-mongodb-native/commit/1147ebf))
22
+ * **sdam:** ignore server errors when closing/closed ([49d7235](https://github.com/mongodb/node-mongodb-native/commit/49d7235))
23
+ * **server:** don't emit error in connect if closing/closed ([62ada2a](https://github.com/mongodb/node-mongodb-native/commit/62ada2a))
24
+ * **server:** ensure state is transitioned to closed on connect fail ([a471707](https://github.com/mongodb/node-mongodb-native/commit/a471707))
25
+ * **topology:** report unified topology as `nodejs` ([d126665](https://github.com/mongodb/node-mongodb-native/commit/d126665))
26
+ * **topology:** set max listeners to infinity for db event relay ([edb1335](https://github.com/mongodb/node-mongodb-native/commit/edb1335))
27
+
28
+
29
+ ### Features
30
+
31
+ * **sdam_viz:** add new tool for visualizing driver sdam changes ([738189a](https://github.com/mongodb/node-mongodb-native/commit/738189a))
32
+ * **sdam_viz:** support legacy topologies in sdam_viz tool ([1a5537e](https://github.com/mongodb/node-mongodb-native/commit/1a5537e))
33
+ * **update-hints:** add support for `hint` to all update methods ([720f5e5](https://github.com/mongodb/node-mongodb-native/commit/720f5e5))
34
+
35
+
36
+
37
+ <a name="3.3.3"></a>
38
+ ## [3.3.3](https://github.com/mongodb/node-mongodb-native/compare/v3.3.2...v3.3.3) (2019-10-16)
39
+
40
+
41
+ ### Bug Fixes
42
+
43
+ * **change_stream:** emit 'close' event if reconnecting failed ([f24c084](https://github.com/mongodb/node-mongodb-native/commit/f24c084))
44
+ * **ChangeStream:** remove startAtOperationTime once we have resumeToken ([362afd8](https://github.com/mongodb/node-mongodb-native/commit/362afd8))
45
+ * **connect:** Switch new Buffer(size) -> Buffer.alloc(size) ([da90c3a](https://github.com/mongodb/node-mongodb-native/commit/da90c3a))
46
+ * **MongoClient:** only check own properties for valid options ([9cde4b9](https://github.com/mongodb/node-mongodb-native/commit/9cde4b9))
47
+ * **mongos:** disconnect proxies which are not mongos instances ([ee53983](https://github.com/mongodb/node-mongodb-native/commit/ee53983))
48
+ * **mongos:** force close servers during reconnect flow ([186263f](https://github.com/mongodb/node-mongodb-native/commit/186263f))
49
+ * **monitoring:** correct spelling mistake for heartbeat event ([21aa117](https://github.com/mongodb/node-mongodb-native/commit/21aa117))
50
+ * **replset:** correct server leak on initial connect ([da39d1e](https://github.com/mongodb/node-mongodb-native/commit/da39d1e))
51
+ * **replset:** destroy primary before removing from replsetstate ([45ac09a](https://github.com/mongodb/node-mongodb-native/commit/45ac09a))
52
+ * **replset:** destroy servers that are removed during SDAM flow ([9ea0190](https://github.com/mongodb/node-mongodb-native/commit/9ea0190))
53
+ * **saslprep:** add in missing saslprep dependency ([41f1165](https://github.com/mongodb/node-mongodb-native/commit/41f1165))
54
+ * **topology:** don't early abort server selection on network errors ([2b6a359](https://github.com/mongodb/node-mongodb-native/commit/2b6a359))
55
+ * **topology:** don't emit server closed event on network error ([194dcf0](https://github.com/mongodb/node-mongodb-native/commit/194dcf0))
56
+ * **topology:** include all BSON types in ctor for bson-ext support ([aa4c832](https://github.com/mongodb/node-mongodb-native/commit/aa4c832))
57
+ * **topology:** respect the `force` parameter for topology close ([d6e8936](https://github.com/mongodb/node-mongodb-native/commit/d6e8936))
58
+
59
+ ### Features
60
+
61
+ * **Update:** add the ability to specify a pipeline to an update command ([#2017](https://github.com/mongodb/node-mongodb-native/issues/2017)) ([44a4110](https://github.com/mongodb/node-mongodb-native/commit/44a4110))
62
+ * **urlParser:** default useNewUrlParser to true ([52d76e3](https://github.com/mongodb/node-mongodb-native/commit/52d76e3))
63
+
64
+ <a name="3.2.7"></a>
65
+ ## [3.2.7](https://github.com/mongodb/node-mongodb-native/compare/v3.2.6...v3.2.7) (2019-06-04)
66
+
67
+
68
+ ### Bug Fixes
69
+
70
+ * **core:** updating core to version 3.2.7 ([2f91466](https://github.com/mongodb/node-mongodb-native/commit/2f91466))
71
+ * **findOneAndReplace:** throw error if atomic operators provided for findOneAndReplace ([6a860a3](https://github.com/mongodb/node-mongodb-native/commit/6a860a3))
72
+
73
+
74
+
75
+ <a name="3.3.2"></a>
76
+ ## [3.3.2](https://github.com/mongodb/node-mongodb-native/compare/v3.3.1...v3.3.2) (2019-08-28)
77
+
78
+
79
+ ### Bug Fixes
80
+
81
+ * **change-stream:** default to server default batch size ([b3ae4c5](https://github.com/mongodb/node-mongodb-native/commit/b3ae4c5))
82
+ * **execute-operation:** return promise on session support check ([a976c14](https://github.com/mongodb/node-mongodb-native/commit/a976c14))
83
+ * **gridfs-stream:** ensure `close` is emitted after last chunk ([ae94cb9](https://github.com/mongodb/node-mongodb-native/commit/ae94cb9))
84
+
85
+
86
+
5
87
  <a name="3.3.1"></a>
6
88
  ## [3.3.1](https://github.com/mongodb/node-mongodb-native/compare/v3.3.0...v3.3.1) (2019-08-23)
7
89
 
@@ -61,7 +61,7 @@ class AggregationCursor extends Cursor {
61
61
  /**
62
62
  * Set the batch size for the cursor.
63
63
  * @method
64
- * @param {number} value The batchSize for the cursor.
64
+ * @param {number} value The number of documents to return per batch. See {@link https://docs.mongodb.com/manual/reference/command/aggregate|aggregation documentation}.
65
65
  * @throws {MongoError}
66
66
  * @return {AggregationCursor}
67
67
  */
@@ -55,60 +55,69 @@ class Batch {
55
55
  }
56
56
 
57
57
  /**
58
- * Create a new BulkWriteResult instance (INTERNAL TYPE, do not instantiate directly)
59
- *
60
- * @class
61
- * @return {BulkWriteResult} a BulkWriteResult instance
58
+ * @classdesc
59
+ * The result of a bulk write.
62
60
  */
63
61
  class BulkWriteResult {
62
+ /**
63
+ * Create a new BulkWriteResult instance
64
+ *
65
+ * **NOTE:** Internal Type, do not instantiate directly
66
+ */
64
67
  constructor(bulkResult) {
65
68
  this.result = bulkResult;
66
69
  }
67
70
 
68
71
  /**
69
- * @return {boolean} ok Did bulk operation correctly execute
72
+ * Evaluates to true if the bulk operation correctly executes
73
+ * @type {boolean}
70
74
  */
71
75
  get ok() {
72
76
  return this.result.ok;
73
77
  }
74
78
 
75
79
  /**
76
- * @return {number} nInserted number of inserted documents
80
+ * The number of inserted documents
81
+ * @type {number}
77
82
  */
78
83
  get nInserted() {
79
84
  return this.result.nInserted;
80
85
  }
81
86
 
82
87
  /**
83
- * @return {number} nUpserted Number of upserted documents
88
+ * Number of upserted documents
89
+ * @type {number}
84
90
  */
85
91
  get nUpserted() {
86
92
  return this.result.nUpserted;
87
93
  }
88
94
 
89
95
  /**
90
- * @return {number} nMatched Number of matched documents
96
+ * Number of matched documents
97
+ * @type {number}
91
98
  */
92
99
  get nMatched() {
93
100
  return this.result.nMatched;
94
101
  }
95
102
 
96
103
  /**
97
- * @return {number} nModified Number of documents updated physically on disk
104
+ * Number of documents updated physically on disk
105
+ * @type {number}
98
106
  */
99
107
  get nModified() {
100
108
  return this.result.nModified;
101
109
  }
102
110
 
103
111
  /**
104
- * @return {number} nRemoved Number of removed documents
112
+ * Number of removed documents
113
+ * @type {number}
105
114
  */
106
115
  get nRemoved() {
107
116
  return this.result.nRemoved;
108
117
  }
109
118
 
110
119
  /**
111
- * Return an array of inserted ids
120
+ * Returns an array of all inserted ids
112
121
  *
113
122
  * @return {object[]}
114
123
  */
@@ -117,7 +126,7 @@ class BulkWriteResult {
117
126
  }
118
127
 
119
128
  /**
120
- * Return an array of upserted ids
129
+ * Returns an array of all upserted ids
121
130
  *
122
131
  * @return {object[]}
123
132
  */
@@ -126,7 +135,7 @@ class BulkWriteResult {
126
135
  }
127
136
 
128
137
  /**
129
- * Return the upserted id at position x
138
+ * Returns the upserted id at the given index
130
139
  *
131
140
  * @param {number} index the number of the upserted id to return, returns undefined if no result for passed in index
132
141
  * @return {object}
@@ -136,7 +145,7 @@ class BulkWriteResult {
136
145
  }
137
146
 
138
147
  /**
139
- * Return raw internal result
148
+ * Returns raw internal result
140
149
  *
141
150
  * @return {object}
142
151
  */
@@ -178,7 +187,7 @@ class BulkWriteResult {
178
187
  /**
179
188
  * Retrieve all write errors
180
189
  *
181
- * @return {object[]}
190
+ * @return {WriteError[]}
182
191
  */
183
192
  getWriteErrors() {
184
193
  return this.result.writeErrors;
@@ -220,7 +229,7 @@ class BulkWriteResult {
220
229
  }
221
230
 
222
231
  /**
223
- * @return {BulkWriteResult} a BulkWriteResult instance
232
+ * @return {object}
224
233
  */
225
234
  toJSON() {
226
235
  return this.result;
@@ -242,25 +251,29 @@ class BulkWriteResult {
242
251
  }
243
252
 
244
253
  /**
245
- * Create a new WriteConcernError instance (INTERNAL TYPE, do not instantiate directly)
246
- *
247
- * @class
248
- * @return {WriteConcernError} a WriteConcernError instance
254
+ * @classdesc An error representing a failure by the server to apply the requested write concern to the bulk operation.
249
255
  */
250
256
  class WriteConcernError {
257
+ /**
258
+ * Create a new WriteConcernError instance
259
+ *
260
+ * **NOTE:** Internal Type, do not instantiate directly
261
+ */
251
262
  constructor(err) {
252
263
  this.err = err;
253
264
  }
254
265
 
255
266
  /**
256
- * @return {number} code Write concern error code.
267
+ * Write concern error code.
268
+ * @type {number}
257
269
  */
258
270
  get code() {
259
271
  return this.err.code;
260
272
  }
261
273
 
262
274
  /**
263
- * @return {string} errmsg Write concern error message.
275
+ * Write concern error message.
276
+ * @type {string}
264
277
  */
265
278
  get errmsg() {
266
279
  return this.err.errmsg;
@@ -282,39 +295,44 @@ class WriteConcernError {
282
295
  }
283
296
 
284
297
  /**
285
- * Create a new WriteError instance (INTERNAL TYPE, do not instantiate directly)
286
- *
287
- * @class
288
- * @return {WriteConcernError} a WriteConcernError instance
298
+ * @classdesc An error that occurred during a BulkWrite on the server.
289
299
  */
290
300
  class WriteError {
301
+ /**
302
+ * Create a new WriteError instance
303
+ *
304
+ * **NOTE:** Internal Type, do not instantiate directly
305
+ */
291
306
  constructor(err) {
292
307
  this.err = err;
293
308
  }
294
309
 
295
310
  /**
296
- * @return {number} code Write concern error code.
311
+ * WriteError code.
312
+ * @type {number}
297
313
  */
298
314
  get code() {
299
315
  return this.err.code;
300
316
  }
301
317
 
302
318
  /**
303
- * @return {number} index Write concern error original bulk operation index.
319
+ * WriteError original bulk operation index.
320
+ * @type {number}
304
321
  */
305
322
  get index() {
306
323
  return this.err.index;
307
324
  }
308
325
 
309
326
  /**
310
- * @return {string} errmsg Write concern error message.
327
+ * WriteError message.
328
+ * @type {string}
311
329
  */
312
330
  get errmsg() {
313
331
  return this.err.errmsg;
314
332
  }
315
333
 
316
334
  /**
317
- * Define access methods
335
+ * Returns the underlying operation that caused the error
318
336
  * @return {object}
319
337
  */
320
338
  getOperation() {
@@ -510,6 +528,7 @@ function executeCommands(bulkOperation, options, callback) {
510
528
  /**
511
529
  * handles write concern error
512
530
  *
531
+ * @ignore
513
532
  * @param {object} batch
514
533
  * @param {object} bulkResult
515
534
  * @param {boolean} ordered
@@ -531,15 +550,16 @@ function handleMongoWriteConcernError(batch, bulkResult, err, callback) {
531
550
  }
532
551
 
533
552
  /**
534
- * Creates a new BulkWriteError
535
- *
536
- * @class
537
- * @param {Error|string|object} message The error message
538
- * @param {BulkWriteResult} result The result of the bulk write operation
539
- * @return {BulkWriteError} A BulkWriteError instance
540
- * @extends {MongoError}
553
+ * @classdesc An error indicating an unsuccessful Bulk Write
541
554
  */
542
555
  class BulkWriteError extends MongoError {
556
+ /**
557
+ * Creates a new BulkWriteError
558
+ *
559
+ * @param {Error|string|object} message The error message
560
+ * @param {BulkWriteResult} result The result of the bulk write operation
561
+ * @extends {MongoError}
562
+ */
543
563
  constructor(error, result) {
544
564
  const message = error.err || error.errmsg || error.errMessage || error;
545
565
  super(message);
@@ -552,11 +572,14 @@ class BulkWriteError extends MongoError {
552
572
  }
553
573
 
554
574
  /**
555
- * Handles the find operators for the bulk operations
556
- * @class
575
+ * @classdesc A builder object that is returned from {@link BulkOperationBase#find}.
576
+ * Is used to build a write operation that involves a query filter.
557
577
  */
558
578
  class FindOperators {
559
579
  /**
580
+ * Creates a new FindOperators object.
581
+ *
582
+ * **NOTE:** Internal Type, do not instantiate directly
560
583
  * @param {OrderedBulkOperation|UnorderedBulkOperation} bulkOperation
561
584
  */
562
585
  constructor(bulkOperation) {
@@ -564,12 +587,13 @@ class FindOperators {
564
587
  }
565
588
 
566
589
  /**
567
- * Add a single update document to the bulk operation
590
+ * Add a multiple update operation to the bulk operation
568
591
  *
569
592
  * @method
570
- * @param {object} updateDocument update operations
571
- * @throws {MongoError}
572
- * @return {OrderedBulkOperation|UnordedBulkOperation}
593
+ * @param {object} updateDocument An update field for an update operation. See {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-u u documentation}
594
+ * @param {object} [options.hint] An optional hint for query optimization. See the {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-hint|update command} reference for more information.
595
+ * @throws {MongoError} If operation cannot be added to bulk write
596
+ * @return {OrderedBulkOperation|UnorderedBulkOperation} A reference to the parent BulkOperation
573
597
  */
574
598
  update(updateDocument) {
575
599
  // Perform upsert
@@ -583,18 +607,23 @@ class FindOperators {
583
607
  upsert: upsert
584
608
  };
585
609
 
610
+ if (updateDocument.hint) {
611
+ document.hint = updateDocument.hint;
612
+ }
613
+
586
614
  // Clear out current Op
587
615
  this.s.currentOp = null;
588
616
  return this.s.options.addToOperationsList(this, UPDATE, document);
589
617
  }
590
618
 
591
619
  /**
592
- * Add a single update one document to the bulk operation
620
+ * Add a single update operation to the bulk operation
593
621
  *
594
622
  * @method
595
- * @param {object} updateDocument update operations
596
- * @throws {MongoError}
597
- * @return {OrderedBulkOperation|UnordedBulkOperation}
623
+ * @param {object} updateDocument An update field for an update operation. See {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-u u documentation}
624
+ * @param {object} [options.hint] An optional hint for query optimization. See the {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-hint|update command} reference for more information.
625
+ * @throws {MongoError} If operation cannot be added to bulk write
626
+ * @return {OrderedBulkOperation|UnorderedBulkOperation} A reference to the parent BulkOperation
598
627
  */
599
628
  updateOne(updateDocument) {
600
629
  // Perform upsert
@@ -608,6 +637,10 @@ class FindOperators {
608
637
  upsert: upsert
609
638
  };
610
639
 
640
+ if (updateDocument.hint) {
641
+ document.hint = updateDocument.hint;
642
+ }
643
+
611
644
  // Clear out current Op
612
645
  this.s.currentOp = null;
613
646
  return this.s.options.addToOperationsList(this, UPDATE, document);
@@ -618,19 +651,19 @@ class FindOperators {
618
651
  *
619
652
  * @method
620
653
  * @param {object} updateDocument the new document to replace the existing one with
621
- * @throws {MongoError}
622
- * @return {OrderedBulkOperation|UnorderedBulkOperation}
654
+ * @throws {MongoError} If operation cannot be added to bulk write
655
+ * @return {OrderedBulkOperation|UnorderedBulkOperation} A reference to the parent BulkOperation
623
656
  */
624
657
  replaceOne(updateDocument) {
625
658
  this.updateOne(updateDocument);
626
659
  }
627
660
 
628
661
  /**
629
- * Upsert modifier for update bulk operation
662
+ * Upsert modifier for update bulk operation, noting that this operation is an upsert.
630
663
  *
631
664
  * @method
632
- * @throws {MongoError}
633
- * @return {FindOperators}
665
+ * @throws {MongoError} If operation cannot be added to bulk write
666
+ * @return {FindOperators} reference to self
634
667
  */
635
668
  upsert() {
636
669
  this.s.currentOp.upsert = true;
@@ -641,8 +674,8 @@ class FindOperators {
641
674
  * Add a delete one operation to the bulk operation
642
675
  *
643
676
  * @method
644
- * @throws {MongoError}
645
- * @return {OrderedBulkOperation|UnordedBulkOperation}
677
+ * @throws {MongoError} If operation cannot be added to bulk write
678
+ * @return {OrderedBulkOperation|UnorderedBulkOperation} A reference to the parent BulkOperation
646
679
  */
647
680
  deleteOne() {
648
681
  // Establish the update command
@@ -657,11 +690,11 @@ class FindOperators {
657
690
  }
658
691
 
659
692
  /**
660
- * Add a delete operation to the bulk operation
693
+ * Add a delete many operation to the bulk operation
661
694
  *
662
695
  * @method
663
- * @throws {MongoError}
664
- * @return {OrderedBulkOperation|UnordedBulkOperation}
696
+ * @throws {MongoError} If operation cannot be added to bulk write
697
+ * @return {OrderedBulkOperation|UnorderedBulkOperation} A reference to the parent BulkOperation
665
698
  */
666
699
  delete() {
667
700
  // Establish the update command
@@ -691,15 +724,14 @@ class FindOperators {
691
724
  }
692
725
 
693
726
  /**
694
- * Parent class to OrderedBulkOperation and UnorderedBulkOperation
695
- * @class
727
+ * @classdesc Parent class to OrderedBulkOperation and UnorderedBulkOperation
728
+ *
729
+ * **NOTE:** Internal Type, do not instantiate directly
696
730
  */
697
731
  class BulkOperationBase {
698
732
  /**
699
- * Create a new OrderedBulkOperation or UnorderedBulkOperation instance (INTERNAL TYPE, do not instantiate directly)
700
- * @class
733
+ * Create a new OrderedBulkOperation or UnorderedBulkOperation instance
701
734
  * @property {number} length Get the number of operations in the bulk.
702
- * @return {OrderedBulkOperation|UnordedBulkOperation}
703
735
  */
704
736
  constructor(topology, collection, options, isOrdered) {
705
737
  // determine whether bulkOperation is ordered or unordered
@@ -809,7 +841,16 @@ class BulkOperationBase {
809
841
  *
810
842
  * @param {object} document the document to insert
811
843
  * @throws {MongoError}
812
- * @return {OrderedBulkOperation|UnorderedBulkOperation}
844
+ * @return {BulkOperationBase} A reference to self
845
+ *
846
+ * @example
847
+ * const bulkOp = collection.initializeOrderedBulkOp();
848
+ * // Adds three inserts to the bulkOp.
849
+ * bulkOp
850
+ * .insert({ a: 1 })
851
+ * .insert({ b: 2 })
852
+ * .insert({ c: 3 });
853
+ * await bulkOp.execute();
813
854
  */
814
855
  insert(document) {
815
856
  if (this.s.collection.s.db.options.forceServerObjectId !== true && document._id == null)
@@ -818,11 +859,42 @@ class BulkOperationBase {
818
859
  }
819
860
 
820
861
  /**
821
- * Initiate a find operation for an update/updateOne/remove/removeOne/replaceOne
862
+ * Builds a find operation for an update/updateOne/delete/deleteOne/replaceOne.
863
+ * Returns a builder object used to complete the definition of the operation.
822
864
  *
823
865
  * @method
824
- * @param {object} selector The selector for the bulk operation.
825
- * @throws {MongoError}
866
+ * @param {object} selector The selector for the bulk operation. See {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-q q documentation}
867
+ * @throws {MongoError} if a selector is not specified
868
+ * @return {FindOperators} A helper object with which the write operation can be defined.
869
+ *
870
+ * @example
871
+ * const bulkOp = collection.initializeOrderedBulkOp();
872
+ *
873
+ * // Add an updateOne to the bulkOp
874
+ * bulkOp.find({ a: 1 }).updateOne({ $set: { b: 2 } });
875
+ *
876
+ * // Add an updateMany to the bulkOp
877
+ * bulkOp.find({ c: 3 }).update({ $set: { d: 4 } });
878
+ *
879
+ * // Add an upsert
880
+ * bulkOp.find({ e: 5 }).upsert().updateOne({ $set: { f: 6 } });
881
+ *
882
+ * // Add a deletion
883
+ * bulkOp.find({ g: 7 }).deleteOne();
884
+ *
885
+ * // Add a multi deletion
886
+ * bulkOp.find({ h: 8 }).delete();
887
+ *
888
+ * // Add a replaceOne
889
+ * bulkOp.find({ i: 9 }).replaceOne({ j: 10 });
890
+ *
891
+ * // Update using a pipeline (requires Mongodb 4.2 or higher)
892
+ * bulk.find({ k: 11, y: { $exists: true }, z: { $exists: true } }).updateOne([
893
+ * { $set: { total: { $sum: [ '$y', '$z' ] } } }
894
+ * ]);
895
+ *
896
+ * // All of the ops will now be executed
897
+ * await bulkOp.execute();
826
898
  */
827
899
  find(selector) {
828
900
  if (!selector) {
@@ -838,11 +910,12 @@ class BulkOperationBase {
838
910
  }
839
911
 
840
912
  /**
841
- * Raw performs the bulk operation
913
+ * Specifies a raw operation to perform in the bulk write.
842
914
  *
843
915
  * @method
844
- * @param {object} op operation
845
- * @return {OrderedBulkOperation|UnorderedBulkOperation}
916
+ * @param {object} op The raw operation to perform.
917
+ * @param {object} [options.hint] An optional hint for query optimization. See the {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-hint|update command} reference for more information.
918
+ * @return {BulkOperationBase} A reference to self
846
919
  */
847
920
  raw(op) {
848
921
  const key = Object.keys(op)[0];
@@ -871,6 +944,11 @@ class BulkOperationBase {
871
944
  u: op[key].update || op[key].replacement,
872
945
  multi: multi
873
946
  };
947
+
948
+ if (op[key].hint) {
949
+ operation.hint = op[key].hint;
950
+ }
951
+
874
952
  if (this.isOrdered) {
875
953
  operation.upsert = op[key].upsert ? true : false;
876
954
  if (op.collation) operation.collation = op.collation;
@@ -929,6 +1007,12 @@ class BulkOperationBase {
929
1007
  );
930
1008
  }
931
1009
 
1010
+ /**
1011
+ * helper function to assist with promiseOrCallback behavior
1012
+ * @ignore
1013
+ * @param {*} err
1014
+ * @param {*} callback
1015
+ */
932
1016
  _handleEarlyError(err, callback) {
933
1017
  if (typeof callback === 'function') {
934
1018
  callback(err, null);
@@ -939,8 +1023,9 @@ class BulkOperationBase {
939
1023
  }
940
1024
 
941
1025
  /**
942
- * Execute next write command in a chain
1026
+ * An internal helper method. Do not invoke directly. Will be going away in the future
943
1027
  *
1028
+ * @ignore
944
1029
  * @method
945
1030
  * @param {class} bulk either OrderedBulkOperation or UnorderdBulkOperation
946
1031
  * @param {object} writeConcern
@@ -984,19 +1069,21 @@ class BulkOperationBase {
984
1069
  * @param {MongoError} error An error instance representing the error during the execution.
985
1070
  * @param {BulkWriteResult} result The bulk write result.
986
1071
  */
1072
+
987
1073
  /**
988
- * Execute the ordered bulk operation
1074
+ * Execute the bulk operation
989
1075
  *
990
1076
  * @method
1077
+ * @param {WriteConcern} [_writeConcern] Optional write concern. Can also be specified through options.
991
1078
  * @param {object} [options] Optional settings.
992
1079
  * @param {(number|string)} [options.w] The write concern.
993
1080
  * @param {number} [options.wtimeout] The write concern timeout.
994
1081
  * @param {boolean} [options.j=false] Specify a journal write concern.
995
1082
  * @param {boolean} [options.fsync=false] Specify a file sync write concern.
996
- * @param {BulkOperationBase~resultCallback} [callback] The result callback
1083
+ * @param {BulkOperationBase~resultCallback} [callback] A callback that will be invoked when bulkWrite finishes/errors
997
1084
  * @throws {MongoError} Throws error if the bulk object has already been executed
998
1085
  * @throws {MongoError} Throws error if the bulk object does not have any operations
999
- * @return {Promise} returns Promise if no callback passed
1086
+ * @return {Promise|void} returns Promise if no callback passed
1000
1087
  */
1001
1088
  execute(_writeConcern, options, callback) {
1002
1089
  const ret = this.bulkExecute(_writeConcern, options, callback);
@@ -1013,6 +1100,9 @@ class BulkOperationBase {
1013
1100
  /**
1014
1101
  * Handles final options before executing command
1015
1102
  *
1103
+ * An internal method. Do not invoke. Will not be accessible in the future
1104
+ *
1105
+ * @ignore
1016
1106
  * @param {object} config
1017
1107
  * @param {object} config.options
1018
1108
  * @param {number} config.batch
@@ -1100,6 +1190,9 @@ class BulkOperationBase {
1100
1190
  /**
1101
1191
  * Handles the write error before executing commands
1102
1192
  *
1193
+ * An internal helper method. Do not invoke directly. Will be going away in the future
1194
+ *
1195
+ * @ignore
1103
1196
  * @param {function} callback
1104
1197
  * @param {BulkWriteResult} writeResult
1105
1198
  * @param {class} self either OrderedBulkOperation or UnorderdBulkOperation
@@ -10,6 +10,7 @@ const toError = utils.toError;
10
10
  /**
11
11
  * Add to internal list of Operations
12
12
  *
13
+ * @ignore
13
14
  * @param {OrderedBulkOperation} bulkOperation
14
15
  * @param {number} docType number indicating the document type
15
16
  * @param {object} document
@@ -82,7 +83,6 @@ function addToOperationsList(bulkOperation, docType, document) {
82
83
  * @property {number} length Get the number of operations in the bulk.
83
84
  * @return {OrderedBulkOperation} a OrderedBulkOperation instance.
84
85
  */
85
-
86
86
  class OrderedBulkOperation extends BulkOperationBase {
87
87
  constructor(topology, collection, options) {
88
88
  options = options || {};
@@ -10,6 +10,7 @@ const toError = utils.toError;
10
10
  /**
11
11
  * Add to internal list of Operations
12
12
  *
13
+ * @ignore
13
14
  * @param {UnorderedBulkOperation} bulkOperation
14
15
  * @param {number} docType number indicating the document type
15
16
  * @param {object} document