mongodb 3.3.2 → 3.3.3
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.
- package/HISTORY.md +38 -0
- package/lib/aggregation_cursor.js +1 -1
- package/lib/bulk/common.js +150 -73
- package/lib/bulk/ordered.js +1 -1
- package/lib/bulk/unordered.js +1 -0
- package/lib/change_stream.js +1 -1
- package/lib/collection.js +65 -14
- package/lib/command_cursor.js +1 -1
- package/lib/core/connection/connection.js +7 -3
- package/lib/core/connection/msg.js +3 -2
- package/lib/core/connection/pool.js +114 -143
- package/lib/core/cursor.js +1 -1
- package/lib/core/error.js +6 -1
- package/lib/core/sdam/monitoring.js +8 -1
- package/lib/core/sdam/server.js +24 -4
- package/lib/core/sdam/topology.js +48 -20
- package/lib/core/sdam/topology_description.js +1 -1
- package/lib/core/topologies/mongos.js +72 -24
- package/lib/core/topologies/replset.js +8 -0
- package/lib/core/topologies/replset_state.js +5 -5
- package/lib/core/topologies/server.js +5 -0
- package/lib/core/topologies/shared.js +1 -0
- package/lib/core/uri_parser.js +8 -2
- package/lib/core/utils.js +6 -1
- package/lib/cursor.js +1 -1
- package/lib/db.js +3 -3
- package/lib/gridfs-stream/index.js +1 -1
- package/lib/mongo_client.js +2 -2
- package/lib/operations/connect.js +15 -12
- package/lib/operations/replace_one.js +1 -1
- package/package.json +9 -5
package/HISTORY.md
CHANGED
|
@@ -2,6 +2,44 @@
|
|
|
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.3"></a>
|
|
6
|
+
## [3.3.3](https://github.com/mongodb/node-mongodb-native/compare/v3.3.2...v3.3.3) (2019-10-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **change_stream:** emit 'close' event if reconnecting failed ([f24c084](https://github.com/mongodb/node-mongodb-native/commit/f24c084))
|
|
12
|
+
* **ChangeStream:** remove startAtOperationTime once we have resumeToken ([362afd8](https://github.com/mongodb/node-mongodb-native/commit/362afd8))
|
|
13
|
+
* **connect:** Switch new Buffer(size) -> Buffer.alloc(size) ([da90c3a](https://github.com/mongodb/node-mongodb-native/commit/da90c3a))
|
|
14
|
+
* **MongoClient:** only check own properties for valid options ([9cde4b9](https://github.com/mongodb/node-mongodb-native/commit/9cde4b9))
|
|
15
|
+
* **mongos:** disconnect proxies which are not mongos instances ([ee53983](https://github.com/mongodb/node-mongodb-native/commit/ee53983))
|
|
16
|
+
* **mongos:** force close servers during reconnect flow ([186263f](https://github.com/mongodb/node-mongodb-native/commit/186263f))
|
|
17
|
+
* **monitoring:** correct spelling mistake for heartbeat event ([21aa117](https://github.com/mongodb/node-mongodb-native/commit/21aa117))
|
|
18
|
+
* **replset:** correct server leak on initial connect ([da39d1e](https://github.com/mongodb/node-mongodb-native/commit/da39d1e))
|
|
19
|
+
* **replset:** destroy primary before removing from replsetstate ([45ac09a](https://github.com/mongodb/node-mongodb-native/commit/45ac09a))
|
|
20
|
+
* **replset:** destroy servers that are removed during SDAM flow ([9ea0190](https://github.com/mongodb/node-mongodb-native/commit/9ea0190))
|
|
21
|
+
* **saslprep:** add in missing saslprep dependency ([41f1165](https://github.com/mongodb/node-mongodb-native/commit/41f1165))
|
|
22
|
+
* **topology:** don't early abort server selection on network errors ([2b6a359](https://github.com/mongodb/node-mongodb-native/commit/2b6a359))
|
|
23
|
+
* **topology:** don't emit server closed event on network error ([194dcf0](https://github.com/mongodb/node-mongodb-native/commit/194dcf0))
|
|
24
|
+
* **topology:** include all BSON types in ctor for bson-ext support ([aa4c832](https://github.com/mongodb/node-mongodb-native/commit/aa4c832))
|
|
25
|
+
* **topology:** respect the `force` parameter for topology close ([d6e8936](https://github.com/mongodb/node-mongodb-native/commit/d6e8936))
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
|
|
29
|
+
* **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))
|
|
30
|
+
* **urlParser:** default useNewUrlParser to true ([52d76e3](https://github.com/mongodb/node-mongodb-native/commit/52d76e3))
|
|
31
|
+
|
|
32
|
+
<a name="3.2.7"></a>
|
|
33
|
+
## [3.2.7](https://github.com/mongodb/node-mongodb-native/compare/v3.2.6...v3.2.7) (2019-06-04)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Bug Fixes
|
|
37
|
+
|
|
38
|
+
* **core:** updating core to version 3.2.7 ([2f91466](https://github.com/mongodb/node-mongodb-native/commit/2f91466))
|
|
39
|
+
* **findOneAndReplace:** throw error if atomic operators provided for findOneAndReplace ([6a860a3](https://github.com/mongodb/node-mongodb-native/commit/6a860a3))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
5
43
|
<a name="3.3.2"></a>
|
|
6
44
|
## [3.3.2](https://github.com/mongodb/node-mongodb-native/compare/v3.3.1...v3.3.2) (2019-08-28)
|
|
7
45
|
|
|
@@ -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
|
|
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
|
*/
|
package/lib/bulk/common.js
CHANGED
|
@@ -55,60 +55,69 @@ class Batch {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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 {
|
|
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 {
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
556
|
-
*
|
|
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,12 @@ class FindOperators {
|
|
|
564
587
|
}
|
|
565
588
|
|
|
566
589
|
/**
|
|
567
|
-
* Add a
|
|
590
|
+
* Add a multiple update operation to the bulk operation
|
|
568
591
|
*
|
|
569
592
|
* @method
|
|
570
|
-
* @param {object} updateDocument update
|
|
571
|
-
* @throws {MongoError}
|
|
572
|
-
* @return {OrderedBulkOperation|
|
|
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
|
+
* @throws {MongoError} If operation cannot be added to bulk write
|
|
595
|
+
* @return {OrderedBulkOperation|UnorderedBulkOperation} A reference to the parent BulkOperation
|
|
573
596
|
*/
|
|
574
597
|
update(updateDocument) {
|
|
575
598
|
// Perform upsert
|
|
@@ -589,12 +612,12 @@ class FindOperators {
|
|
|
589
612
|
}
|
|
590
613
|
|
|
591
614
|
/**
|
|
592
|
-
* Add a single update
|
|
615
|
+
* Add a single update operation to the bulk operation
|
|
593
616
|
*
|
|
594
617
|
* @method
|
|
595
|
-
* @param {object} updateDocument update
|
|
596
|
-
* @throws {MongoError}
|
|
597
|
-
* @return {OrderedBulkOperation|
|
|
618
|
+
* @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}
|
|
619
|
+
* @throws {MongoError} If operation cannot be added to bulk write
|
|
620
|
+
* @return {OrderedBulkOperation|UnorderedBulkOperation} A reference to the parent BulkOperation
|
|
598
621
|
*/
|
|
599
622
|
updateOne(updateDocument) {
|
|
600
623
|
// Perform upsert
|
|
@@ -618,19 +641,19 @@ class FindOperators {
|
|
|
618
641
|
*
|
|
619
642
|
* @method
|
|
620
643
|
* @param {object} updateDocument the new document to replace the existing one with
|
|
621
|
-
* @throws {MongoError}
|
|
622
|
-
* @return {OrderedBulkOperation|UnorderedBulkOperation}
|
|
644
|
+
* @throws {MongoError} If operation cannot be added to bulk write
|
|
645
|
+
* @return {OrderedBulkOperation|UnorderedBulkOperation} A reference to the parent BulkOperation
|
|
623
646
|
*/
|
|
624
647
|
replaceOne(updateDocument) {
|
|
625
648
|
this.updateOne(updateDocument);
|
|
626
649
|
}
|
|
627
650
|
|
|
628
651
|
/**
|
|
629
|
-
* Upsert modifier for update bulk operation
|
|
652
|
+
* Upsert modifier for update bulk operation, noting that this operation is an upsert.
|
|
630
653
|
*
|
|
631
654
|
* @method
|
|
632
|
-
* @throws {MongoError}
|
|
633
|
-
* @return {FindOperators}
|
|
655
|
+
* @throws {MongoError} If operation cannot be added to bulk write
|
|
656
|
+
* @return {FindOperators} reference to self
|
|
634
657
|
*/
|
|
635
658
|
upsert() {
|
|
636
659
|
this.s.currentOp.upsert = true;
|
|
@@ -641,8 +664,8 @@ class FindOperators {
|
|
|
641
664
|
* Add a delete one operation to the bulk operation
|
|
642
665
|
*
|
|
643
666
|
* @method
|
|
644
|
-
* @throws {MongoError}
|
|
645
|
-
* @return {OrderedBulkOperation|
|
|
667
|
+
* @throws {MongoError} If operation cannot be added to bulk write
|
|
668
|
+
* @return {OrderedBulkOperation|UnorderedBulkOperation} A reference to the parent BulkOperation
|
|
646
669
|
*/
|
|
647
670
|
deleteOne() {
|
|
648
671
|
// Establish the update command
|
|
@@ -657,11 +680,11 @@ class FindOperators {
|
|
|
657
680
|
}
|
|
658
681
|
|
|
659
682
|
/**
|
|
660
|
-
* Add a delete operation to the bulk operation
|
|
683
|
+
* Add a delete many operation to the bulk operation
|
|
661
684
|
*
|
|
662
685
|
* @method
|
|
663
|
-
* @throws {MongoError}
|
|
664
|
-
* @return {OrderedBulkOperation|
|
|
686
|
+
* @throws {MongoError} If operation cannot be added to bulk write
|
|
687
|
+
* @return {OrderedBulkOperation|UnorderedBulkOperation} A reference to the parent BulkOperation
|
|
665
688
|
*/
|
|
666
689
|
delete() {
|
|
667
690
|
// Establish the update command
|
|
@@ -691,15 +714,14 @@ class FindOperators {
|
|
|
691
714
|
}
|
|
692
715
|
|
|
693
716
|
/**
|
|
694
|
-
* Parent class to OrderedBulkOperation and UnorderedBulkOperation
|
|
695
|
-
*
|
|
717
|
+
* @classdesc Parent class to OrderedBulkOperation and UnorderedBulkOperation
|
|
718
|
+
*
|
|
719
|
+
* **NOTE:** Internal Type, do not instantiate directly
|
|
696
720
|
*/
|
|
697
721
|
class BulkOperationBase {
|
|
698
722
|
/**
|
|
699
|
-
* Create a new OrderedBulkOperation or UnorderedBulkOperation instance
|
|
700
|
-
* @class
|
|
723
|
+
* Create a new OrderedBulkOperation or UnorderedBulkOperation instance
|
|
701
724
|
* @property {number} length Get the number of operations in the bulk.
|
|
702
|
-
* @return {OrderedBulkOperation|UnordedBulkOperation}
|
|
703
725
|
*/
|
|
704
726
|
constructor(topology, collection, options, isOrdered) {
|
|
705
727
|
// determine whether bulkOperation is ordered or unordered
|
|
@@ -809,7 +831,16 @@ class BulkOperationBase {
|
|
|
809
831
|
*
|
|
810
832
|
* @param {object} document the document to insert
|
|
811
833
|
* @throws {MongoError}
|
|
812
|
-
* @return {
|
|
834
|
+
* @return {BulkOperationBase} A reference to self
|
|
835
|
+
*
|
|
836
|
+
* @example
|
|
837
|
+
* const bulkOp = collection.initializeOrderedBulkOp();
|
|
838
|
+
* // Adds three inserts to the bulkOp.
|
|
839
|
+
* bulkOp
|
|
840
|
+
* .insert({ a: 1 })
|
|
841
|
+
* .insert({ b: 2 })
|
|
842
|
+
* .insert({ c: 3 });
|
|
843
|
+
* await bulkOp.execute();
|
|
813
844
|
*/
|
|
814
845
|
insert(document) {
|
|
815
846
|
if (this.s.collection.s.db.options.forceServerObjectId !== true && document._id == null)
|
|
@@ -818,11 +849,42 @@ class BulkOperationBase {
|
|
|
818
849
|
}
|
|
819
850
|
|
|
820
851
|
/**
|
|
821
|
-
*
|
|
852
|
+
* Builds a find operation for an update/updateOne/delete/deleteOne/replaceOne.
|
|
853
|
+
* Returns a builder object used to complete the definition of the operation.
|
|
822
854
|
*
|
|
823
855
|
* @method
|
|
824
|
-
* @param {object} selector The selector for the bulk operation.
|
|
825
|
-
* @throws {MongoError}
|
|
856
|
+
* @param {object} selector The selector for the bulk operation. See {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-q q documentation}
|
|
857
|
+
* @throws {MongoError} if a selector is not specified
|
|
858
|
+
* @return {FindOperators} A helper object with which the write operation can be defined.
|
|
859
|
+
*
|
|
860
|
+
* @example
|
|
861
|
+
* const bulkOp = collection.initializeOrderedBulkOp();
|
|
862
|
+
*
|
|
863
|
+
* // Add an updateOne to the bulkOp
|
|
864
|
+
* bulkOp.find({ a: 1 }).updateOne({ $set: { b: 2 } });
|
|
865
|
+
*
|
|
866
|
+
* // Add an updateMany to the bulkOp
|
|
867
|
+
* bulkOp.find({ c: 3 }).update({ $set: { d: 4 } });
|
|
868
|
+
*
|
|
869
|
+
* // Add an upsert
|
|
870
|
+
* bulkOp.find({ e: 5 }).upsert().updateOne({ $set: { f: 6 } });
|
|
871
|
+
*
|
|
872
|
+
* // Add a deletion
|
|
873
|
+
* bulkOp.find({ g: 7 }).deleteOne();
|
|
874
|
+
*
|
|
875
|
+
* // Add a multi deletion
|
|
876
|
+
* bulkOp.find({ h: 8 }).delete();
|
|
877
|
+
*
|
|
878
|
+
* // Add a replaceOne
|
|
879
|
+
* bulkOp.find({ i: 9 }).replaceOne({ j: 10 });
|
|
880
|
+
*
|
|
881
|
+
* // Update using a pipeline (requires Mongodb 4.2 or higher)
|
|
882
|
+
* bulk.find({ k: 11, y: { $exists: true }, z: { $exists: true } }).updateOne([
|
|
883
|
+
* { $set: { total: { $sum: [ '$y', '$z' ] } } }
|
|
884
|
+
* ]);
|
|
885
|
+
*
|
|
886
|
+
* // All of the ops will now be executed
|
|
887
|
+
* await bulkOp.execute();
|
|
826
888
|
*/
|
|
827
889
|
find(selector) {
|
|
828
890
|
if (!selector) {
|
|
@@ -838,11 +900,11 @@ class BulkOperationBase {
|
|
|
838
900
|
}
|
|
839
901
|
|
|
840
902
|
/**
|
|
841
|
-
*
|
|
903
|
+
* Specifies a raw operation to perform in the bulk write.
|
|
842
904
|
*
|
|
843
905
|
* @method
|
|
844
|
-
* @param {object} op operation
|
|
845
|
-
* @return {
|
|
906
|
+
* @param {object} op The raw operation to perform.
|
|
907
|
+
* @return {BulkOperationBase} A reference to self
|
|
846
908
|
*/
|
|
847
909
|
raw(op) {
|
|
848
910
|
const key = Object.keys(op)[0];
|
|
@@ -929,6 +991,12 @@ class BulkOperationBase {
|
|
|
929
991
|
);
|
|
930
992
|
}
|
|
931
993
|
|
|
994
|
+
/**
|
|
995
|
+
* helper function to assist with promiseOrCallback behavior
|
|
996
|
+
* @ignore
|
|
997
|
+
* @param {*} err
|
|
998
|
+
* @param {*} callback
|
|
999
|
+
*/
|
|
932
1000
|
_handleEarlyError(err, callback) {
|
|
933
1001
|
if (typeof callback === 'function') {
|
|
934
1002
|
callback(err, null);
|
|
@@ -939,8 +1007,9 @@ class BulkOperationBase {
|
|
|
939
1007
|
}
|
|
940
1008
|
|
|
941
1009
|
/**
|
|
942
|
-
*
|
|
1010
|
+
* An internal helper method. Do not invoke directly. Will be going away in the future
|
|
943
1011
|
*
|
|
1012
|
+
* @ignore
|
|
944
1013
|
* @method
|
|
945
1014
|
* @param {class} bulk either OrderedBulkOperation or UnorderdBulkOperation
|
|
946
1015
|
* @param {object} writeConcern
|
|
@@ -984,19 +1053,21 @@ class BulkOperationBase {
|
|
|
984
1053
|
* @param {MongoError} error An error instance representing the error during the execution.
|
|
985
1054
|
* @param {BulkWriteResult} result The bulk write result.
|
|
986
1055
|
*/
|
|
1056
|
+
|
|
987
1057
|
/**
|
|
988
|
-
* Execute the
|
|
1058
|
+
* Execute the bulk operation
|
|
989
1059
|
*
|
|
990
1060
|
* @method
|
|
1061
|
+
* @param {WriteConcern} [_writeConcern] Optional write concern. Can also be specified through options.
|
|
991
1062
|
* @param {object} [options] Optional settings.
|
|
992
1063
|
* @param {(number|string)} [options.w] The write concern.
|
|
993
1064
|
* @param {number} [options.wtimeout] The write concern timeout.
|
|
994
1065
|
* @param {boolean} [options.j=false] Specify a journal write concern.
|
|
995
1066
|
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
|
|
996
|
-
* @param {BulkOperationBase~resultCallback} [callback]
|
|
1067
|
+
* @param {BulkOperationBase~resultCallback} [callback] A callback that will be invoked when bulkWrite finishes/errors
|
|
997
1068
|
* @throws {MongoError} Throws error if the bulk object has already been executed
|
|
998
1069
|
* @throws {MongoError} Throws error if the bulk object does not have any operations
|
|
999
|
-
* @return {Promise} returns Promise if no callback passed
|
|
1070
|
+
* @return {Promise|void} returns Promise if no callback passed
|
|
1000
1071
|
*/
|
|
1001
1072
|
execute(_writeConcern, options, callback) {
|
|
1002
1073
|
const ret = this.bulkExecute(_writeConcern, options, callback);
|
|
@@ -1013,6 +1084,9 @@ class BulkOperationBase {
|
|
|
1013
1084
|
/**
|
|
1014
1085
|
* Handles final options before executing command
|
|
1015
1086
|
*
|
|
1087
|
+
* An internal method. Do not invoke. Will not be accessible in the future
|
|
1088
|
+
*
|
|
1089
|
+
* @ignore
|
|
1016
1090
|
* @param {object} config
|
|
1017
1091
|
* @param {object} config.options
|
|
1018
1092
|
* @param {number} config.batch
|
|
@@ -1100,6 +1174,9 @@ class BulkOperationBase {
|
|
|
1100
1174
|
/**
|
|
1101
1175
|
* Handles the write error before executing commands
|
|
1102
1176
|
*
|
|
1177
|
+
* An internal helper method. Do not invoke directly. Will be going away in the future
|
|
1178
|
+
*
|
|
1179
|
+
* @ignore
|
|
1103
1180
|
* @param {function} callback
|
|
1104
1181
|
* @param {BulkWriteResult} writeResult
|
|
1105
1182
|
* @param {class} self either OrderedBulkOperation or UnorderdBulkOperation
|
package/lib/bulk/ordered.js
CHANGED
|
@@ -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 || {};
|
package/lib/bulk/unordered.js
CHANGED
package/lib/change_stream.js
CHANGED
|
@@ -39,7 +39,7 @@ const CHANGE_DOMAIN_TYPES = {
|
|
|
39
39
|
* @property {ResumeToken} [resumeAfter] Allows you to start a changeStream after a specified event. See {@link https://docs.mongodb.com/master/changeStreams/#resumeafter-for-change-streams|ChangeStream documentation}.
|
|
40
40
|
* @property {ResumeToken} [startAfter] Similar to resumeAfter, but will allow you to start after an invalidated event. See {@link https://docs.mongodb.com/master/changeStreams/#startafter-for-change-streams|ChangeStream documentation}.
|
|
41
41
|
* @property {OperationTime} [startAtOperationTime] Will start the changeStream after the specified operationTime.
|
|
42
|
-
* @property {number} [batchSize] The number of documents to return per batch. See {@link https://docs.mongodb.com/manual/reference/command/aggregate|aggregation documentation}.
|
|
42
|
+
* @property {number} [batchSize=1000] The number of documents to return per batch. See {@link https://docs.mongodb.com/manual/reference/command/aggregate|aggregation documentation}.
|
|
43
43
|
* @property {object} [collation] Specify collation settings for operation. See {@link https://docs.mongodb.com/manual/reference/command/aggregate|aggregation documentation}.
|
|
44
44
|
* @property {ReadPreference} [readPreference] The read preference. Defaults to the read preference of the database or collection. See {@link https://docs.mongodb.com/manual/reference/read-preference|read preference documentation}.
|
|
45
45
|
*/
|