mongodb 3.2.3 → 3.2.7
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 +49 -0
- package/README.md +2 -3
- package/lib/.DS_Store +0 -0
- package/lib/bulk/common.js +77 -38
- package/lib/bulk/ordered.js +3 -84
- package/lib/bulk/unordered.js +3 -109
- package/lib/collection.js +20 -2
- package/lib/gridfs-stream/download.js +6 -7
- package/lib/mongo_client.js +1 -1
- package/lib/topologies/native_topology.js +4 -3
- package/package.json +2 -2
package/HISTORY.md
CHANGED
|
@@ -2,6 +2,55 @@
|
|
|
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.2.7"></a>
|
|
6
|
+
## [3.2.7](https://github.com/mongodb/node-mongodb-native/compare/v3.2.6...v3.2.7) (2019-06-04)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **core:** updating core to version 3.2.7 ([2f91466](https://github.com/mongodb/node-mongodb-native/commit/2f91466))
|
|
12
|
+
* **findOneAndReplace:** throw error if atomic operators provided for findOneAndReplace ([6a860a3](https://github.com/mongodb/node-mongodb-native/commit/6a860a3))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
<a name="3.2.6"></a>
|
|
17
|
+
## [3.2.6](https://github.com/mongodb/node-mongodb-native/compare/v3.2.5...v3.2.6) (2019-05-24)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
<a name="3.2.5"></a>
|
|
22
|
+
## [3.2.5](https://github.com/mongodb/node-mongodb-native/compare/v3.2.4...v3.2.5) (2019-05-17)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* **core:** updating core to 3.2.5 ([a2766c1](https://github.com/mongodb/node-mongodb-native/commit/a2766c1))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
<a name="3.2.4"></a>
|
|
32
|
+
## [3.2.4](https://github.com/mongodb/node-mongodb-native/compare/v3.2.2...v3.2.4) (2019-05-08)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### Bug Fixes
|
|
36
|
+
|
|
37
|
+
* **aggregation:** fix field name typo ([4235d04](https://github.com/mongodb/node-mongodb-native/commit/4235d04))
|
|
38
|
+
* **async:** rewrote asyncGenerator in node < 10 syntax ([49c8cef](https://github.com/mongodb/node-mongodb-native/commit/49c8cef))
|
|
39
|
+
* **BulkOp:** run unordered bulk ops in serial ([f548bd7](https://github.com/mongodb/node-mongodb-native/commit/f548bd7))
|
|
40
|
+
* **bulkWrite:** fix issue with bulkWrite continuing w/ callback ([2a4a42c](https://github.com/mongodb/node-mongodb-native/commit/2a4a42c))
|
|
41
|
+
* **docs:** correctly document that default for `sslValidate` is false ([1f8e7fa](https://github.com/mongodb/node-mongodb-native/commit/1f8e7fa))
|
|
42
|
+
* **gridfs-stream:** honor chunk size ([9eeb114](https://github.com/mongodb/node-mongodb-native/commit/9eeb114))
|
|
43
|
+
* **unified-topology:** only clone pool size if provided ([8dc2416](https://github.com/mongodb/node-mongodb-native/commit/8dc2416))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### Features
|
|
47
|
+
|
|
48
|
+
* update to mongodb-core v3.2.3 ([1c5357a](https://github.com/mongodb/node-mongodb-native/commit/1c5357a))
|
|
49
|
+
* **core:** update to mongodb-core v3.2.4 ([2059260](https://github.com/mongodb/node-mongodb-native/commit/2059260))
|
|
50
|
+
* **lib:** implement executeOperationV2 ([67d4edf](https://github.com/mongodb/node-mongodb-native/commit/67d4edf))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
5
54
|
<a name="3.2.3"></a>
|
|
6
55
|
## [3.2.3](https://github.com/mongodb/node-mongodb-native/compare/v3.2.2...v3.2.3) (2019-04-05)
|
|
7
56
|
|
package/README.md
CHANGED
|
@@ -31,10 +31,9 @@ case in our issue management tool, JIRA:
|
|
|
31
31
|
Bug reports in JIRA for all driver projects (i.e. NODE, PYTHON, CSHARP, JAVA) and the
|
|
32
32
|
Core Server (i.e. SERVER) project are **public**.
|
|
33
33
|
|
|
34
|
-
###
|
|
34
|
+
### Support / Feedback
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
* JIRA: [jira.mongodb.org](http://jira.mongodb.org)
|
|
36
|
+
For issues with, questions about, or feedback for the Node.js driver, please look into our [support channels](http://www.mongodb.org/about/support). Please do not email any of the driver developers directly with issues or questions - you're more likely to get an answer on the [mongodb-user](http://groups.google.com/group/mongodb-user>) list on Google Groups.
|
|
38
37
|
|
|
39
38
|
### Change Log
|
|
40
39
|
|
package/lib/.DS_Store
ADDED
|
Binary file
|
package/lib/bulk/common.js
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
const Long = require('mongodb-core').BSON.Long;
|
|
4
4
|
const MongoError = require('mongodb-core').MongoError;
|
|
5
|
+
const ObjectID = require('mongodb-core').BSON.ObjectID;
|
|
6
|
+
const BSON = require('mongodb-core').BSON;
|
|
7
|
+
const MongoWriteConcernError = require('mongodb-core').MongoWriteConcernError;
|
|
5
8
|
const toError = require('../utils').toError;
|
|
6
9
|
const handleCallback = require('../utils').handleCallback;
|
|
7
10
|
const applyRetryableWrites = require('../utils').applyRetryableWrites;
|
|
8
11
|
const applyWriteConcern = require('../utils').applyWriteConcern;
|
|
9
|
-
const
|
|
10
|
-
const
|
|
12
|
+
const executeOperation = require('../utils').executeOperation;
|
|
13
|
+
const isPromiseLike = require('../utils').isPromiseLike;
|
|
11
14
|
|
|
12
15
|
// Error codes
|
|
13
|
-
const UNKNOWN_ERROR = 8;
|
|
14
|
-
const INVALID_BSON_ERROR = 22;
|
|
15
16
|
const WRITE_CONCERN_ERROR = 64;
|
|
16
|
-
const MULTIPLE_ERROR = 65;
|
|
17
17
|
|
|
18
18
|
// Insert types
|
|
19
19
|
const INSERT = 1;
|
|
@@ -54,18 +54,6 @@ class Batch {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
/**
|
|
58
|
-
* Wraps a legacy operation so we can correctly rewrite its error
|
|
59
|
-
* @ignore
|
|
60
|
-
*/
|
|
61
|
-
class LegacyOp {
|
|
62
|
-
constructor(batchType, operation, index) {
|
|
63
|
-
this.batchType = batchType;
|
|
64
|
-
this.index = index;
|
|
65
|
-
this.operation = operation;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
57
|
/**
|
|
70
58
|
* Create a new BulkWriteResult instance (INTERNAL TYPE, do not instantiate directly)
|
|
71
59
|
*
|
|
@@ -352,7 +340,7 @@ class WriteError {
|
|
|
352
340
|
* Merges results into shared data structure
|
|
353
341
|
* @ignore
|
|
354
342
|
*/
|
|
355
|
-
function mergeBatchResults(
|
|
343
|
+
function mergeBatchResults(batch, bulkResult, err, result) {
|
|
356
344
|
// If we have an error set the result to be the err object
|
|
357
345
|
if (err) {
|
|
358
346
|
result = err;
|
|
@@ -484,6 +472,41 @@ function mergeBatchResults(ordered, batch, bulkResult, err, result) {
|
|
|
484
472
|
}
|
|
485
473
|
}
|
|
486
474
|
|
|
475
|
+
function executeCommands(bulkOperation, options, callback) {
|
|
476
|
+
if (bulkOperation.s.batches.length === 0) {
|
|
477
|
+
return handleCallback(callback, null, new BulkWriteResult(bulkOperation.s.bulkResult));
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const batch = bulkOperation.s.batches.shift();
|
|
481
|
+
|
|
482
|
+
function resultHandler(err, result) {
|
|
483
|
+
// Error is a driver related error not a bulk op error, terminate
|
|
484
|
+
if (((err && err.driver) || (err && err.message)) && !(err instanceof MongoWriteConcernError)) {
|
|
485
|
+
return handleCallback(callback, err);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// If we have and error
|
|
489
|
+
if (err) err.ok = 0;
|
|
490
|
+
if (err instanceof MongoWriteConcernError) {
|
|
491
|
+
return handleMongoWriteConcernError(batch, bulkOperation.s.bulkResult, err, callback);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// Merge the results together
|
|
495
|
+
const writeResult = new BulkWriteResult(bulkOperation.s.bulkResult);
|
|
496
|
+
const mergeResult = mergeBatchResults(batch, bulkOperation.s.bulkResult, err, result);
|
|
497
|
+
if (mergeResult != null) {
|
|
498
|
+
return handleCallback(callback, null, writeResult);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (bulkOperation.handleWriteError(callback, writeResult)) return;
|
|
502
|
+
|
|
503
|
+
// Execute the next command in line
|
|
504
|
+
executeCommands(bulkOperation, options, callback);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
bulkOperation.finalOptionsHandler({ options, batch, resultHandler }, callback);
|
|
508
|
+
}
|
|
509
|
+
|
|
487
510
|
/**
|
|
488
511
|
* handles write concern error
|
|
489
512
|
*
|
|
@@ -493,8 +516,8 @@ function mergeBatchResults(ordered, batch, bulkResult, err, result) {
|
|
|
493
516
|
* @param {WriteConcernError} err
|
|
494
517
|
* @param {function} callback
|
|
495
518
|
*/
|
|
496
|
-
function handleMongoWriteConcernError(batch, bulkResult,
|
|
497
|
-
mergeBatchResults(
|
|
519
|
+
function handleMongoWriteConcernError(batch, bulkResult, err, callback) {
|
|
520
|
+
mergeBatchResults(batch, bulkResult, null, err.result);
|
|
498
521
|
|
|
499
522
|
const wrappedWriteConcernError = new WriteConcernError({
|
|
500
523
|
errmsg: err.result.writeConcernError.errmsg,
|
|
@@ -955,6 +978,38 @@ class BulkOperationBase {
|
|
|
955
978
|
return { options, callback };
|
|
956
979
|
}
|
|
957
980
|
|
|
981
|
+
/**
|
|
982
|
+
* The callback format for results
|
|
983
|
+
* @callback BulkOperationBase~resultCallback
|
|
984
|
+
* @param {MongoError} error An error instance representing the error during the execution.
|
|
985
|
+
* @param {BulkWriteResult} result The bulk write result.
|
|
986
|
+
*/
|
|
987
|
+
/**
|
|
988
|
+
* Execute the ordered bulk operation
|
|
989
|
+
*
|
|
990
|
+
* @method
|
|
991
|
+
* @param {object} [options] Optional settings.
|
|
992
|
+
* @param {(number|string)} [options.w] The write concern.
|
|
993
|
+
* @param {number} [options.wtimeout] The write concern timeout.
|
|
994
|
+
* @param {boolean} [options.j=false] Specify a journal write concern.
|
|
995
|
+
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
|
|
996
|
+
* @param {BulkOperationBase~resultCallback} [callback] The result callback
|
|
997
|
+
* @throws {MongoError} Throws error if the bulk object has already been executed
|
|
998
|
+
* @throws {MongoError} Throws error if the bulk object does not have any operations
|
|
999
|
+
* @return {Promise} returns Promise if no callback passed
|
|
1000
|
+
*/
|
|
1001
|
+
execute(_writeConcern, options, callback) {
|
|
1002
|
+
const ret = this.bulkExecute(_writeConcern, options, callback);
|
|
1003
|
+
if (!ret || isPromiseLike(ret)) {
|
|
1004
|
+
return ret;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
options = ret.options;
|
|
1008
|
+
callback = ret.callback;
|
|
1009
|
+
|
|
1010
|
+
return executeOperation(this.s.topology, executeCommands, [this, options, callback]);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
958
1013
|
/**
|
|
959
1014
|
* Handles final options before executing command
|
|
960
1015
|
*
|
|
@@ -1038,11 +1093,7 @@ class BulkOperationBase {
|
|
|
1038
1093
|
// Force top level error
|
|
1039
1094
|
err.ok = 0;
|
|
1040
1095
|
// Merge top level error and return
|
|
1041
|
-
handleCallback(
|
|
1042
|
-
callback,
|
|
1043
|
-
null,
|
|
1044
|
-
mergeBatchResults(false, config.batch, this.s.bulkResult, err, null)
|
|
1045
|
-
);
|
|
1096
|
+
handleCallback(callback, null, mergeBatchResults(config.batch, this.s.bulkResult, err, null));
|
|
1046
1097
|
}
|
|
1047
1098
|
}
|
|
1048
1099
|
|
|
@@ -1099,20 +1150,8 @@ Object.defineProperty(BulkOperationBase.prototype, 'length', {
|
|
|
1099
1150
|
module.exports = {
|
|
1100
1151
|
Batch,
|
|
1101
1152
|
BulkOperationBase,
|
|
1102
|
-
BulkWriteError,
|
|
1103
|
-
BulkWriteResult,
|
|
1104
1153
|
bson,
|
|
1105
|
-
FindOperators,
|
|
1106
|
-
handleMongoWriteConcernError,
|
|
1107
|
-
LegacyOp,
|
|
1108
|
-
mergeBatchResults,
|
|
1109
|
-
INVALID_BSON_ERROR: INVALID_BSON_ERROR,
|
|
1110
|
-
MULTIPLE_ERROR: MULTIPLE_ERROR,
|
|
1111
|
-
UNKNOWN_ERROR: UNKNOWN_ERROR,
|
|
1112
|
-
WRITE_CONCERN_ERROR: WRITE_CONCERN_ERROR,
|
|
1113
1154
|
INSERT: INSERT,
|
|
1114
1155
|
UPDATE: UPDATE,
|
|
1115
|
-
REMOVE: REMOVE
|
|
1116
|
-
WriteError,
|
|
1117
|
-
WriteConcernError
|
|
1156
|
+
REMOVE: REMOVE
|
|
1118
1157
|
};
|
package/lib/bulk/ordered.js
CHANGED
|
@@ -2,17 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const common = require('./common');
|
|
4
4
|
const BulkOperationBase = common.BulkOperationBase;
|
|
5
|
-
const utils = require('../utils');
|
|
6
|
-
const toError = utils.toError;
|
|
7
|
-
const handleCallback = utils.handleCallback;
|
|
8
|
-
const BulkWriteResult = common.BulkWriteResult;
|
|
9
5
|
const Batch = common.Batch;
|
|
10
|
-
const mergeBatchResults = common.mergeBatchResults;
|
|
11
|
-
const executeOperation = utils.executeOperation;
|
|
12
|
-
const MongoWriteConcernError = require('mongodb-core').MongoWriteConcernError;
|
|
13
|
-
const handleMongoWriteConcernError = require('./common').handleMongoWriteConcernError;
|
|
14
6
|
const bson = common.bson;
|
|
15
|
-
const
|
|
7
|
+
const utils = require('../utils');
|
|
8
|
+
const toError = utils.toError;
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
11
|
* Add to internal list of Operations
|
|
@@ -85,6 +78,7 @@ function addToOperationsList(bulkOperation, docType, document) {
|
|
|
85
78
|
/**
|
|
86
79
|
* Create a new OrderedBulkOperation instance (INTERNAL TYPE, do not instantiate directly)
|
|
87
80
|
* @class
|
|
81
|
+
* @extends BulkOperationBase
|
|
88
82
|
* @property {number} length Get the number of operations in the bulk.
|
|
89
83
|
* @return {OrderedBulkOperation} a OrderedBulkOperation instance.
|
|
90
84
|
*/
|
|
@@ -96,81 +90,6 @@ class OrderedBulkOperation extends BulkOperationBase {
|
|
|
96
90
|
|
|
97
91
|
super(topology, collection, options, true);
|
|
98
92
|
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* The callback format for results
|
|
102
|
-
* @callback OrderedBulkOperation~resultCallback
|
|
103
|
-
* @param {MongoError} error An error instance representing the error during the execution.
|
|
104
|
-
* @param {BulkWriteResult} result The bulk write result.
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Execute the ordered bulk operation
|
|
109
|
-
*
|
|
110
|
-
* @method
|
|
111
|
-
* @param {object} [options] Optional settings.
|
|
112
|
-
* @param {(number|string)} [options.w] The write concern.
|
|
113
|
-
* @param {number} [options.wtimeout] The write concern timeout.
|
|
114
|
-
* @param {boolean} [options.j=false] Specify a journal write concern.
|
|
115
|
-
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
|
|
116
|
-
* @param {OrderedBulkOperation~resultCallback} [callback] The result callback
|
|
117
|
-
* @throws {MongoError}
|
|
118
|
-
* @return {Promise} returns Promise if no callback passed
|
|
119
|
-
*/
|
|
120
|
-
execute(_writeConcern, options, callback) {
|
|
121
|
-
const ret = this.bulkExecute(_writeConcern, options, callback);
|
|
122
|
-
if (!ret || isPromiseLike(ret)) {
|
|
123
|
-
return ret;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
options = ret.options;
|
|
127
|
-
callback = ret.callback;
|
|
128
|
-
|
|
129
|
-
return executeOperation(this.s.topology, executeCommands, [this, options, callback]);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Execute next write command in a chain
|
|
135
|
-
*
|
|
136
|
-
* @param {OrderedBulkOperation} bulkOperation
|
|
137
|
-
* @param {object} options
|
|
138
|
-
* @param {function} callback
|
|
139
|
-
*/
|
|
140
|
-
function executeCommands(bulkOperation, options, callback) {
|
|
141
|
-
if (bulkOperation.s.batches.length === 0) {
|
|
142
|
-
return handleCallback(callback, null, new BulkWriteResult(bulkOperation.s.bulkResult));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Ordered execution of the command
|
|
146
|
-
const batch = bulkOperation.s.batches.shift();
|
|
147
|
-
|
|
148
|
-
function resultHandler(err, result) {
|
|
149
|
-
// Error is a driver related error not a bulk op error, terminate
|
|
150
|
-
if (((err && err.driver) || (err && err.message)) && !(err instanceof MongoWriteConcernError)) {
|
|
151
|
-
return handleCallback(callback, err);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// If we have and error
|
|
155
|
-
if (err) err.ok = 0;
|
|
156
|
-
if (err instanceof MongoWriteConcernError) {
|
|
157
|
-
return handleMongoWriteConcernError(batch, bulkOperation.s.bulkResult, true, err, callback);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Merge the results together
|
|
161
|
-
const writeResult = new BulkWriteResult(bulkOperation.s.bulkResult);
|
|
162
|
-
const mergeResult = mergeBatchResults(true, batch, bulkOperation.s.bulkResult, err, result);
|
|
163
|
-
if (mergeResult != null) {
|
|
164
|
-
return handleCallback(callback, null, writeResult);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (bulkOperation.handleWriteError(callback, writeResult)) return;
|
|
168
|
-
|
|
169
|
-
// Execute the next command in line
|
|
170
|
-
executeCommands(bulkOperation, options, callback);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
bulkOperation.finalOptionsHandler({ options, batch, resultHandler }, callback);
|
|
174
93
|
}
|
|
175
94
|
|
|
176
95
|
/**
|
package/lib/bulk/unordered.js
CHANGED
|
@@ -2,17 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const common = require('./common');
|
|
4
4
|
const BulkOperationBase = common.BulkOperationBase;
|
|
5
|
-
const utils = require('../utils');
|
|
6
|
-
const toError = utils.toError;
|
|
7
|
-
const handleCallback = utils.handleCallback;
|
|
8
|
-
const BulkWriteResult = common.BulkWriteResult;
|
|
9
5
|
const Batch = common.Batch;
|
|
10
|
-
const mergeBatchResults = common.mergeBatchResults;
|
|
11
|
-
const executeOperation = utils.executeOperation;
|
|
12
|
-
const MongoWriteConcernError = require('mongodb-core').MongoWriteConcernError;
|
|
13
|
-
const handleMongoWriteConcernError = require('./common').handleMongoWriteConcernError;
|
|
14
6
|
const bson = common.bson;
|
|
15
|
-
const
|
|
7
|
+
const utils = require('../utils');
|
|
8
|
+
const toError = utils.toError;
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
11
|
* Add to internal list of Operations
|
|
@@ -98,6 +91,7 @@ function addToOperationsList(bulkOperation, docType, document) {
|
|
|
98
91
|
/**
|
|
99
92
|
* Create a new UnorderedBulkOperation instance (INTERNAL TYPE, do not instantiate directly)
|
|
100
93
|
* @class
|
|
94
|
+
* @extends BulkOperationBase
|
|
101
95
|
* @property {number} length Get the number of operations in the bulk.
|
|
102
96
|
* @return {UnorderedBulkOperation} a UnorderedBulkOperation instance.
|
|
103
97
|
*/
|
|
@@ -108,106 +102,6 @@ class UnorderedBulkOperation extends BulkOperationBase {
|
|
|
108
102
|
|
|
109
103
|
super(topology, collection, options, false);
|
|
110
104
|
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* The callback format for results
|
|
114
|
-
* @callback UnorderedBulkOperation~resultCallback
|
|
115
|
-
* @param {MongoError} error An error instance representing the error during the execution.
|
|
116
|
-
* @param {BulkWriteResult} result The bulk write result.
|
|
117
|
-
*/
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Execute the ordered bulk operation
|
|
121
|
-
*
|
|
122
|
-
* @method
|
|
123
|
-
* @param {object} [options] Optional settings.
|
|
124
|
-
* @param {(number|string)} [options.w] The write concern.
|
|
125
|
-
* @param {number} [options.wtimeout] The write concern timeout.
|
|
126
|
-
* @param {boolean} [options.j=false] Specify a journal write concern.
|
|
127
|
-
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
|
|
128
|
-
* @param {UnorderedBulkOperation~resultCallback} [callback] The result callback
|
|
129
|
-
* @throws {MongoError}
|
|
130
|
-
* @return {Promise} returns Promise if no callback passed
|
|
131
|
-
*/
|
|
132
|
-
execute(_writeConcern, options, callback) {
|
|
133
|
-
const ret = this.bulkExecute(_writeConcern, options, callback);
|
|
134
|
-
if (!ret || isPromiseLike(ret)) {
|
|
135
|
-
return ret;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
options = ret.options;
|
|
139
|
-
callback = ret.callback;
|
|
140
|
-
|
|
141
|
-
return executeOperation(this.s.topology, executeBatches, [this, options, callback]);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Execute the command
|
|
147
|
-
*
|
|
148
|
-
* @param {UnorderedBulkOperation} bulkOperation
|
|
149
|
-
* @param {object} batch
|
|
150
|
-
* @param {object} options
|
|
151
|
-
* @param {function} callback
|
|
152
|
-
*/
|
|
153
|
-
function executeBatch(bulkOperation, batch, options, callback) {
|
|
154
|
-
function resultHandler(err, result) {
|
|
155
|
-
// Error is a driver related error not a bulk op error, terminate
|
|
156
|
-
if (((err && err.driver) || (err && err.message)) && !(err instanceof MongoWriteConcernError)) {
|
|
157
|
-
return handleCallback(callback, err);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// If we have and error
|
|
161
|
-
if (err) err.ok = 0;
|
|
162
|
-
if (err instanceof MongoWriteConcernError) {
|
|
163
|
-
return handleMongoWriteConcernError(batch, bulkOperation.s.bulkResult, false, err, callback);
|
|
164
|
-
}
|
|
165
|
-
handleCallback(
|
|
166
|
-
callback,
|
|
167
|
-
null,
|
|
168
|
-
mergeBatchResults(false, batch, bulkOperation.s.bulkResult, err, result)
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
bulkOperation.finalOptionsHandler({ options, batch, resultHandler }, callback);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Execute all the commands
|
|
177
|
-
*
|
|
178
|
-
* @param {UnorderedBulkOperation} bulkOperation
|
|
179
|
-
* @param {object} options
|
|
180
|
-
* @param {function} callback
|
|
181
|
-
*/
|
|
182
|
-
function executeBatches(bulkOperation, options, callback) {
|
|
183
|
-
let numberOfCommandsToExecute = bulkOperation.s.batches.length;
|
|
184
|
-
let hasErrored = false;
|
|
185
|
-
// Execute over all the batches
|
|
186
|
-
for (let i = 0; i < bulkOperation.s.batches.length; i++) {
|
|
187
|
-
executeBatch(bulkOperation, bulkOperation.s.batches[i], options, function(err) {
|
|
188
|
-
if (hasErrored) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (err) {
|
|
193
|
-
hasErrored = true;
|
|
194
|
-
return handleCallback(callback, err);
|
|
195
|
-
}
|
|
196
|
-
// Count down the number of commands left to execute
|
|
197
|
-
numberOfCommandsToExecute = numberOfCommandsToExecute - 1;
|
|
198
|
-
|
|
199
|
-
// Execute
|
|
200
|
-
if (numberOfCommandsToExecute === 0) {
|
|
201
|
-
// Driver level error
|
|
202
|
-
if (err) return handleCallback(callback, err);
|
|
203
|
-
|
|
204
|
-
const writeResult = new BulkWriteResult(bulkOperation.s.bulkResult);
|
|
205
|
-
if (bulkOperation.handleWriteError(callback, writeResult)) return;
|
|
206
|
-
|
|
207
|
-
return handleCallback(callback, null, writeResult);
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
105
|
}
|
|
212
106
|
|
|
213
107
|
/**
|
package/lib/collection.js
CHANGED
|
@@ -1515,6 +1515,13 @@ Collection.prototype.findOneAndReplace = function(filter, replacement, options,
|
|
|
1515
1515
|
if (replacement == null || typeof replacement !== 'object')
|
|
1516
1516
|
throw toError('replacement parameter must be an object');
|
|
1517
1517
|
|
|
1518
|
+
// Check that there are no atomic operators
|
|
1519
|
+
const keys = Object.keys(replacement);
|
|
1520
|
+
|
|
1521
|
+
if (keys[0] && keys[0][0] === '$') {
|
|
1522
|
+
throw toError('The replacement document must not contain atomic operators.');
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1518
1525
|
return executeOperation(this.s.topology, findOneAndReplace, [
|
|
1519
1526
|
this,
|
|
1520
1527
|
filter,
|
|
@@ -1587,7 +1594,18 @@ Collection.prototype.findOneAndUpdate = function(filter, update, options, callba
|
|
|
1587
1594
|
* @return {Promise} returns Promise if no callback passed
|
|
1588
1595
|
* @deprecated use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead
|
|
1589
1596
|
*/
|
|
1590
|
-
Collection.prototype.findAndModify = deprecate(
|
|
1597
|
+
Collection.prototype.findAndModify = deprecate(
|
|
1598
|
+
_findAndModify,
|
|
1599
|
+
'collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead.'
|
|
1600
|
+
);
|
|
1601
|
+
|
|
1602
|
+
/**
|
|
1603
|
+
* @ignore
|
|
1604
|
+
*/
|
|
1605
|
+
|
|
1606
|
+
Collection.prototype._findAndModify = _findAndModify;
|
|
1607
|
+
|
|
1608
|
+
function _findAndModify(query, sort, doc, options, callback) {
|
|
1591
1609
|
const args = Array.prototype.slice.call(arguments, 1);
|
|
1592
1610
|
callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
|
|
1593
1611
|
sort = args.length ? args.shift() || [] : [];
|
|
@@ -1607,7 +1625,7 @@ Collection.prototype.findAndModify = deprecate(function(query, sort, doc, option
|
|
|
1607
1625
|
options,
|
|
1608
1626
|
callback
|
|
1609
1627
|
]);
|
|
1610
|
-
}
|
|
1628
|
+
}
|
|
1611
1629
|
|
|
1612
1630
|
/**
|
|
1613
1631
|
* Find and remove a document.
|
|
@@ -234,13 +234,12 @@ function doRead(_this) {
|
|
|
234
234
|
_this.s.bytesToSkip = 0;
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
sliceEnd = _this.s.options.end - _this.s.bytesToSkip;
|
|
237
|
+
const atEndOfStream = expectedN === _this.s.expectedEnd - 1;
|
|
238
|
+
const bytesLeftToRead = _this.s.options.end - _this.s.bytesToSkip;
|
|
239
|
+
if (atEndOfStream && _this.s.bytesToTrim != null) {
|
|
240
|
+
sliceEnd = _this.s.file.chunkSize - _this.s.bytesToTrim;
|
|
241
|
+
} else if (_this.s.options.end && bytesLeftToRead < doc.data.length()) {
|
|
242
|
+
sliceEnd = bytesLeftToRead;
|
|
244
243
|
}
|
|
245
244
|
|
|
246
245
|
if (sliceStart != null || sliceEnd != null) {
|
package/lib/mongo_client.js
CHANGED
|
@@ -185,7 +185,7 @@ MongoClient.prototype.logout = deprecate(function(options, callback) {
|
|
|
185
185
|
/**
|
|
186
186
|
* Close the db and its underlying connections
|
|
187
187
|
* @method
|
|
188
|
-
* @param {boolean} force Force close, emitting no events
|
|
188
|
+
* @param {boolean} [force=false] Force close, emitting no events
|
|
189
189
|
* @param {Db~noResultCallback} [callback] The result callback
|
|
190
190
|
* @return {Promise} returns Promise if no callback passed
|
|
191
191
|
*/
|
|
@@ -14,9 +14,10 @@ class NativeTopology extends Topology {
|
|
|
14
14
|
{
|
|
15
15
|
cursorFactory: Cursor,
|
|
16
16
|
reconnect: false,
|
|
17
|
-
emitError: options.emitError,
|
|
18
|
-
size: options.poolSize,
|
|
19
|
-
monitorCommands:
|
|
17
|
+
emitError: typeof options.emitError === 'boolean' ? options.emitError : true,
|
|
18
|
+
size: typeof options.poolSize === 'number' ? options.poolSize : 5,
|
|
19
|
+
monitorCommands:
|
|
20
|
+
typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false
|
|
20
21
|
}
|
|
21
22
|
);
|
|
22
23
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongodb",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.7",
|
|
4
4
|
"description": "The official MongoDB driver for Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"official"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"mongodb-core": "
|
|
20
|
+
"mongodb-core": "3.2.7",
|
|
21
21
|
"safe-buffer": "^5.1.2"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|