mongodb 3.3.3 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HISTORY.md +90 -0
- package/index.js +4 -0
- package/lib/bulk/common.js +26 -5
- package/lib/bulk/ordered.js +9 -4
- package/lib/bulk/unordered.js +9 -4
- package/lib/collection.js +123 -35
- package/lib/core/auth/scram.js +42 -6
- package/lib/core/cmap/connection.js +220 -0
- package/lib/core/cmap/message_stream.js +181 -0
- package/lib/core/connection/apm.js +14 -16
- package/lib/core/connection/connect.js +56 -39
- package/lib/core/connection/connection.js +17 -1
- package/lib/core/connection/logger.js +9 -4
- package/lib/core/connection/msg.js +1 -1
- package/lib/core/connection/pool.js +123 -86
- package/lib/core/cursor.js +1 -1
- package/lib/core/error.js +17 -6
- package/lib/core/index.js +1 -1
- package/lib/core/sdam/common.js +59 -0
- package/lib/core/sdam/monitoring.js +16 -10
- package/lib/core/sdam/server.js +79 -36
- package/lib/core/sdam/server_description.js +30 -14
- package/lib/core/sdam/{server_selectors.js → server_selection.js} +100 -7
- package/lib/core/sdam/srv_polling.js +1 -1
- package/lib/core/sdam/topology.js +165 -192
- package/lib/core/sdam/topology_description.js +14 -23
- package/lib/core/sessions.js +5 -8
- package/lib/core/topologies/replset.js +26 -15
- package/lib/core/topologies/server.js +8 -12
- package/lib/core/topologies/shared.js +26 -16
- package/lib/core/uri_parser.js +49 -1
- package/lib/core/utils.js +32 -1
- package/lib/core/wireprotocol/command.js +25 -3
- package/lib/core/wireprotocol/compression.js +13 -13
- package/lib/core/wireprotocol/shared.js +1 -1
- package/lib/db.js +3 -1
- package/lib/gridfs/grid_store.js +15 -8
- package/lib/gridfs-stream/download.js +5 -4
- package/lib/gridfs-stream/index.js +3 -2
- package/lib/gridfs-stream/upload.js +3 -3
- package/lib/mongo_client.js +44 -34
- package/lib/operations/close.js +6 -2
- package/lib/operations/command_v2.js +1 -3
- package/lib/operations/common_functions.js +5 -2
- package/lib/operations/connect.js +48 -3
- package/lib/operations/create_collection.js +1 -2
- package/lib/operations/db_ops.js +2 -4
- package/lib/operations/execute_operation.js +2 -1
- package/lib/operations/map_reduce.js +2 -1
- package/lib/utils.js +2 -1
- package/package.json +8 -5
package/HISTORY.md
CHANGED
|
@@ -2,6 +2,96 @@
|
|
|
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.4.0"></a>
|
|
6
|
+
# [3.4.0](https://github.com/mongodb/node-mongodb-native/compare/v3.3.5...v3.4.0) (2019-12-10)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **bulk:** use operation index from input to report operation error ([f713b13](https://github.com/mongodb/node-mongodb-native/commit/f713b13))
|
|
12
|
+
* **command:** only add TransientTransactionError label when in a transaction ([478d714](https://github.com/mongodb/node-mongodb-native/commit/478d714))
|
|
13
|
+
* **compression:** recalculate opcode after determine OP_COMPRESSED ([022f51b](https://github.com/mongodb/node-mongodb-native/commit/022f51b))
|
|
14
|
+
* **connect:** connect with family 0 instead of family 4 ([db07366](https://github.com/mongodb/node-mongodb-native/commit/db07366))
|
|
15
|
+
* **connection:** timed out connections should not be half closed ([850f4f5](https://github.com/mongodb/node-mongodb-native/commit/850f4f5))
|
|
16
|
+
* **cursor:** call `initialize` after session support check ([e50c51a](https://github.com/mongodb/node-mongodb-native/commit/e50c51a))
|
|
17
|
+
* **encryption:** autoEncryption must error on mongodb < 4.2 ([c274615](https://github.com/mongodb/node-mongodb-native/commit/c274615))
|
|
18
|
+
* **encryption:** do not attempt to merge autoEncryption options ([e27fdf9](https://github.com/mongodb/node-mongodb-native/commit/e27fdf9))
|
|
19
|
+
* **encryption:** encryption uses smaller batch size ([cb78e69](https://github.com/mongodb/node-mongodb-native/commit/cb78e69))
|
|
20
|
+
* **encryption:** respect bypassAutoEncryption ([e927499](https://github.com/mongodb/node-mongodb-native/commit/e927499))
|
|
21
|
+
* **encryption:** respect user bson options when using autoEncryption ([cb7a3f7](https://github.com/mongodb/node-mongodb-native/commit/cb7a3f7))
|
|
22
|
+
* add calculated duration to server as `roundTripTime` ([cb107a8](https://github.com/mongodb/node-mongodb-native/commit/cb107a8))
|
|
23
|
+
* **mongodb+srv:** respect overriding SRV-provided properties ([ea83360](https://github.com/mongodb/node-mongodb-native/commit/ea83360))
|
|
24
|
+
* **pool:** flush workItems after next tick to avoid dupe selection ([3ec49e5](https://github.com/mongodb/node-mongodb-native/commit/3ec49e5))
|
|
25
|
+
* **pool:** support a `drain` event for use with unified topology ([da931ea](https://github.com/mongodb/node-mongodb-native/commit/da931ea))
|
|
26
|
+
* **scram:** verify server digest, ensuring mutual authentication ([806cd62](https://github.com/mongodb/node-mongodb-native/commit/806cd62))
|
|
27
|
+
* **srv-poller:** always provide a valid number for `intervalMS` ([afb125f](https://github.com/mongodb/node-mongodb-native/commit/afb125f))
|
|
28
|
+
* **topology:** correct logic for checking for sessions support ([8d157c8](https://github.com/mongodb/node-mongodb-native/commit/8d157c8))
|
|
29
|
+
* **topology:** don't drain iteration timers on server selection ([fed6a57](https://github.com/mongodb/node-mongodb-native/commit/fed6a57))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Features
|
|
33
|
+
|
|
34
|
+
* add `MessageStream` for streamed wire protocol messaging ([8c44044](https://github.com/mongodb/node-mongodb-native/commit/8c44044))
|
|
35
|
+
* introduce a modern `Connection` replacement for CMAP ([7890e48](https://github.com/mongodb/node-mongodb-native/commit/7890e48))
|
|
36
|
+
* support connection establishment cancellation ([2014b7b](https://github.com/mongodb/node-mongodb-native/commit/2014b7b))
|
|
37
|
+
* support driver info for drivers wrapping the node driver ([1b6670b](https://github.com/mongodb/node-mongodb-native/commit/1b6670b))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
<a name="3.3.5"></a>
|
|
42
|
+
## [3.3.5](https://github.com/mongodb/node-mongodb-native/compare/v3.3.4...v3.3.5) (2019-11-26)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Bug Fixes
|
|
46
|
+
|
|
47
|
+
* **bulk:** use operation index from input to report operation error ([08ee53e](https://github.com/mongodb/node-mongodb-native/commit/08ee53e))
|
|
48
|
+
* **command:** only add TransientTransactionError label when in a transaction ([8bab074](https://github.com/mongodb/node-mongodb-native/commit/8bab074))
|
|
49
|
+
* **connect:** connect with family 0 instead of family 4 ([7a41279](https://github.com/mongodb/node-mongodb-native/commit/7a41279))
|
|
50
|
+
* **cursor:** call `initialize` after session support check ([3b076b3](https://github.com/mongodb/node-mongodb-native/commit/3b076b3))
|
|
51
|
+
* **mongodb+srv:** respect overriding SRV-provided properties ([5ed4c07](https://github.com/mongodb/node-mongodb-native/commit/5ed4c07))
|
|
52
|
+
* **pool:** support a `drain` event for use with unified topology ([3471c28](https://github.com/mongodb/node-mongodb-native/commit/3471c28))
|
|
53
|
+
* **topology:** correct logic for checking for sessions support ([2d976bd](https://github.com/mongodb/node-mongodb-native/commit/2d976bd))
|
|
54
|
+
* **topology:** don't drain iteration timers on server selection ([261f1e5](https://github.com/mongodb/node-mongodb-native/commit/261f1e5))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
### Features
|
|
58
|
+
|
|
59
|
+
* support driver info for drivers wrapping the node driver ([d85c4a8](https://github.com/mongodb/node-mongodb-native/commit/d85c4a8))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
<a name="3.3.4"></a>
|
|
64
|
+
## [3.3.4](https://github.com/mongodb/node-mongodb-native/compare/v3.3.3...v3.3.4) (2019-11-11)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### Bug Fixes
|
|
68
|
+
|
|
69
|
+
* **close:** the unified topology emits a close event on close now ([ee0db01](https://github.com/mongodb/node-mongodb-native/commit/ee0db01))
|
|
70
|
+
* **connect:** prevent multiple callbacks in error scenarios ([5f6a787](https://github.com/mongodb/node-mongodb-native/commit/5f6a787))
|
|
71
|
+
* **monitoring:** incorrect states used to determine rescheduling ([ec1e04c](https://github.com/mongodb/node-mongodb-native/commit/ec1e04c))
|
|
72
|
+
* **pool:** don't reset a pool if we'not already connected ([32316e4](https://github.com/mongodb/node-mongodb-native/commit/32316e4))
|
|
73
|
+
* **pool:** only transition to `DISCONNECTED` if reconnect enabled ([43d461e](https://github.com/mongodb/node-mongodb-native/commit/43d461e))
|
|
74
|
+
* **replset:** don't leak servers failing to connect ([f209160](https://github.com/mongodb/node-mongodb-native/commit/f209160))
|
|
75
|
+
* **replset:** use correct `topologyId` for event emission ([19549ff](https://github.com/mongodb/node-mongodb-native/commit/19549ff))
|
|
76
|
+
* **sdam:** `minHeartbeatIntervalMS` => `minHeartbeatFrequencyMS` ([af9fb45](https://github.com/mongodb/node-mongodb-native/commit/af9fb45))
|
|
77
|
+
* **sdam:** don't emit `close` every time a child server closes ([818055a](https://github.com/mongodb/node-mongodb-native/commit/818055a))
|
|
78
|
+
* **sdam:** don't lose servers when they fail monitoring ([8a534bb](https://github.com/mongodb/node-mongodb-native/commit/8a534bb))
|
|
79
|
+
* **sdam:** don't remove unknown servers in topology updates ([1147ebf](https://github.com/mongodb/node-mongodb-native/commit/1147ebf))
|
|
80
|
+
* **sdam:** ignore server errors when closing/closed ([49d7235](https://github.com/mongodb/node-mongodb-native/commit/49d7235))
|
|
81
|
+
* **server:** don't emit error in connect if closing/closed ([62ada2a](https://github.com/mongodb/node-mongodb-native/commit/62ada2a))
|
|
82
|
+
* **server:** ensure state is transitioned to closed on connect fail ([a471707](https://github.com/mongodb/node-mongodb-native/commit/a471707))
|
|
83
|
+
* **topology:** report unified topology as `nodejs` ([d126665](https://github.com/mongodb/node-mongodb-native/commit/d126665))
|
|
84
|
+
* **topology:** set max listeners to infinity for db event relay ([edb1335](https://github.com/mongodb/node-mongodb-native/commit/edb1335))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Features
|
|
88
|
+
|
|
89
|
+
* **sdam_viz:** add new tool for visualizing driver sdam changes ([738189a](https://github.com/mongodb/node-mongodb-native/commit/738189a))
|
|
90
|
+
* **sdam_viz:** support legacy topologies in sdam_viz tool ([1a5537e](https://github.com/mongodb/node-mongodb-native/commit/1a5537e))
|
|
91
|
+
* **update-hints:** add support for `hint` to all update methods ([720f5e5](https://github.com/mongodb/node-mongodb-native/commit/720f5e5))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
5
95
|
<a name="3.3.3"></a>
|
|
6
96
|
## [3.3.3](https://github.com/mongodb/node-mongodb-native/compare/v3.3.2...v3.3.3) (2019-10-16)
|
|
7
97
|
|
package/index.js
CHANGED
|
@@ -11,6 +11,10 @@ const connect = require('./lib/mongo_client').connect;
|
|
|
11
11
|
connect.MongoError = core.MongoError;
|
|
12
12
|
connect.MongoNetworkError = core.MongoNetworkError;
|
|
13
13
|
connect.MongoTimeoutError = core.MongoTimeoutError;
|
|
14
|
+
connect.MongoParseError = core.MongoParseError;
|
|
15
|
+
connect.MongoWriteConcernError = core.MongoWriteConcernError;
|
|
16
|
+
connect.MongoBulkWriteError = require('./lib/bulk/common').BulkWriteError;
|
|
17
|
+
connect.BulkWriteError = connect.MongoBulkWriteError;
|
|
14
18
|
|
|
15
19
|
// Actual driver classes exported
|
|
16
20
|
connect.Admin = require('./lib/admin');
|
package/lib/bulk/common.js
CHANGED
|
@@ -475,7 +475,7 @@ function mergeBatchResults(batch, bulkResult, err, result) {
|
|
|
475
475
|
if (Array.isArray(result.writeErrors)) {
|
|
476
476
|
for (let i = 0; i < result.writeErrors.length; i++) {
|
|
477
477
|
const writeError = {
|
|
478
|
-
index: batch.
|
|
478
|
+
index: batch.originalIndexes[i],
|
|
479
479
|
code: result.writeErrors[i].code,
|
|
480
480
|
errmsg: result.writeErrors[i].errmsg,
|
|
481
481
|
op: batch.operations[result.writeErrors[i].index]
|
|
@@ -591,6 +591,7 @@ class FindOperators {
|
|
|
591
591
|
*
|
|
592
592
|
* @method
|
|
593
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.
|
|
594
595
|
* @throws {MongoError} If operation cannot be added to bulk write
|
|
595
596
|
* @return {OrderedBulkOperation|UnorderedBulkOperation} A reference to the parent BulkOperation
|
|
596
597
|
*/
|
|
@@ -606,6 +607,10 @@ class FindOperators {
|
|
|
606
607
|
upsert: upsert
|
|
607
608
|
};
|
|
608
609
|
|
|
610
|
+
if (updateDocument.hint) {
|
|
611
|
+
document.hint = updateDocument.hint;
|
|
612
|
+
}
|
|
613
|
+
|
|
609
614
|
// Clear out current Op
|
|
610
615
|
this.s.currentOp = null;
|
|
611
616
|
return this.s.options.addToOperationsList(this, UPDATE, document);
|
|
@@ -616,6 +621,7 @@ class FindOperators {
|
|
|
616
621
|
*
|
|
617
622
|
* @method
|
|
618
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.
|
|
619
625
|
* @throws {MongoError} If operation cannot be added to bulk write
|
|
620
626
|
* @return {OrderedBulkOperation|UnorderedBulkOperation} A reference to the parent BulkOperation
|
|
621
627
|
*/
|
|
@@ -631,6 +637,10 @@ class FindOperators {
|
|
|
631
637
|
upsert: upsert
|
|
632
638
|
};
|
|
633
639
|
|
|
640
|
+
if (updateDocument.hint) {
|
|
641
|
+
document.hint = updateDocument.hint;
|
|
642
|
+
}
|
|
643
|
+
|
|
634
644
|
// Clear out current Op
|
|
635
645
|
this.s.currentOp = null;
|
|
636
646
|
return this.s.options.addToOperationsList(this, UPDATE, document);
|
|
@@ -739,11 +749,15 @@ class BulkOperationBase {
|
|
|
739
749
|
|
|
740
750
|
// Handle to the bson serializer, used to calculate running sizes
|
|
741
751
|
const bson = topology.bson;
|
|
742
|
-
|
|
743
752
|
// Set max byte size
|
|
744
753
|
const isMaster = topology.lastIsMaster();
|
|
745
|
-
|
|
754
|
+
|
|
755
|
+
// If we have autoEncryption on, batch-splitting must be done on 2mb chunks, but single documents
|
|
756
|
+
// over 2mb are still allowed
|
|
757
|
+
const usingAutoEncryption = !!(topology.s.options && topology.s.options.autoEncrypter);
|
|
758
|
+
const maxBsonObjectSize =
|
|
746
759
|
isMaster && isMaster.maxBsonObjectSize ? isMaster.maxBsonObjectSize : 1024 * 1024 * 16;
|
|
760
|
+
const maxBatchSizeBytes = usingAutoEncryption ? 1024 * 1024 * 2 : maxBsonObjectSize;
|
|
747
761
|
const maxWriteBatchSize =
|
|
748
762
|
isMaster && isMaster.maxWriteBatchSize ? isMaster.maxWriteBatchSize : 1000;
|
|
749
763
|
|
|
@@ -795,8 +809,9 @@ class BulkOperationBase {
|
|
|
795
809
|
// Write concern
|
|
796
810
|
writeConcern: writeConcern,
|
|
797
811
|
// Max batch size options
|
|
798
|
-
|
|
799
|
-
|
|
812
|
+
maxBsonObjectSize,
|
|
813
|
+
maxBatchSizeBytes,
|
|
814
|
+
maxWriteBatchSize,
|
|
800
815
|
maxKeySize,
|
|
801
816
|
// Namespace
|
|
802
817
|
namespace: namespace,
|
|
@@ -904,6 +919,7 @@ class BulkOperationBase {
|
|
|
904
919
|
*
|
|
905
920
|
* @method
|
|
906
921
|
* @param {object} op The raw operation to perform.
|
|
922
|
+
* @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.
|
|
907
923
|
* @return {BulkOperationBase} A reference to self
|
|
908
924
|
*/
|
|
909
925
|
raw(op) {
|
|
@@ -933,6 +949,11 @@ class BulkOperationBase {
|
|
|
933
949
|
u: op[key].update || op[key].replacement,
|
|
934
950
|
multi: multi
|
|
935
951
|
};
|
|
952
|
+
|
|
953
|
+
if (op[key].hint) {
|
|
954
|
+
operation.hint = op[key].hint;
|
|
955
|
+
}
|
|
956
|
+
|
|
936
957
|
if (this.isOrdered) {
|
|
937
958
|
operation.upsert = op[key].upsert ? true : false;
|
|
938
959
|
if (op.collation) operation.collation = op.collation;
|
package/lib/bulk/ordered.js
CHANGED
|
@@ -27,8 +27,8 @@ function addToOperationsList(bulkOperation, docType, document) {
|
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
// Throw error if the doc is bigger than the max BSON size
|
|
30
|
-
if (bsonSize >= bulkOperation.s.
|
|
31
|
-
throw toError('document is larger than the maximum size ' + bulkOperation.s.
|
|
30
|
+
if (bsonSize >= bulkOperation.s.maxBsonObjectSize)
|
|
31
|
+
throw toError('document is larger than the maximum size ' + bulkOperation.s.maxBsonObjectSize);
|
|
32
32
|
|
|
33
33
|
// Create a new batch object if we don't have a current one
|
|
34
34
|
if (bulkOperation.s.currentBatch == null)
|
|
@@ -38,9 +38,14 @@ function addToOperationsList(bulkOperation, docType, document) {
|
|
|
38
38
|
|
|
39
39
|
// Check if we need to create a new batch
|
|
40
40
|
if (
|
|
41
|
+
// New batch if we exceed the max batch op size
|
|
41
42
|
bulkOperation.s.currentBatchSize + 1 >= bulkOperation.s.maxWriteBatchSize ||
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
// New batch if we exceed the maxBatchSizeBytes. Only matters if batch already has a doc,
|
|
44
|
+
// since we can't sent an empty batch
|
|
45
|
+
(bulkOperation.s.currentBatchSize > 0 &&
|
|
46
|
+
bulkOperation.s.currentBatchSizeBytes + maxKeySize + bsonSize >=
|
|
47
|
+
bulkOperation.s.maxBatchSizeBytes) ||
|
|
48
|
+
// New batch if the new op does not have the same op type as the current batch
|
|
44
49
|
bulkOperation.s.currentBatch.batchType !== docType
|
|
45
50
|
) {
|
|
46
51
|
// Save the batch to the execution stack
|
package/lib/bulk/unordered.js
CHANGED
|
@@ -26,8 +26,8 @@ function addToOperationsList(bulkOperation, docType, document) {
|
|
|
26
26
|
ignoreUndefined: false
|
|
27
27
|
});
|
|
28
28
|
// Throw error if the doc is bigger than the max BSON size
|
|
29
|
-
if (bsonSize >= bulkOperation.s.
|
|
30
|
-
throw toError('document is larger than the maximum size ' + bulkOperation.s.
|
|
29
|
+
if (bsonSize >= bulkOperation.s.maxBsonObjectSize)
|
|
30
|
+
throw toError('document is larger than the maximum size ' + bulkOperation.s.maxBsonObjectSize);
|
|
31
31
|
// Holds the current batch
|
|
32
32
|
bulkOperation.s.currentBatch = null;
|
|
33
33
|
// Get the right type of batch
|
|
@@ -47,9 +47,14 @@ function addToOperationsList(bulkOperation, docType, document) {
|
|
|
47
47
|
|
|
48
48
|
// Check if we need to create a new batch
|
|
49
49
|
if (
|
|
50
|
+
// New batch if we exceed the max batch op size
|
|
50
51
|
bulkOperation.s.currentBatch.size + 1 >= bulkOperation.s.maxWriteBatchSize ||
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
// New batch if we exceed the maxBatchSizeBytes. Only matters if batch already has a doc,
|
|
53
|
+
// since we can't sent an empty batch
|
|
54
|
+
(bulkOperation.s.currentBatch.size > 0 &&
|
|
55
|
+
bulkOperation.s.currentBatch.sizeBytes + maxKeySize + bsonSize >=
|
|
56
|
+
bulkOperation.s.maxBatchSizeBytes) ||
|
|
57
|
+
// New batch if the new op does not have the same op type as the current batch
|
|
53
58
|
bulkOperation.s.currentBatch.batchType !== docType
|
|
54
59
|
) {
|
|
55
60
|
// Save the batch to the execution stack
|