Skip to content

Commit 91a2fc9

Browse files
committed
Merge remote-tracking branch 'origin/3.6' into 3.7
2 parents 93a47fd + 6ee945e commit 91a2fc9

39 files changed

+836
-118
lines changed

HISTORY.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
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.
44

5+
### [3.6.10](https://github.com/mongodb/node-mongodb-native/compare/v3.6.9...v3.6.10) (2021-07-06)
6+
7+
8+
### Bug Fixes
9+
10+
* **NODE-2035:** Exceptions thrown from awaited cursor forEach do not propagate ([#2852](https://github.com/mongodb/node-mongodb-native/issues/2852)) ([a917dfa](https://github.com/mongodb/node-mongodb-native/commit/a917dfada67859412344ed238796cf3bee243f5f))
11+
* **NODE-3150:** added bsonRegExp option for v3.6 ([#2843](https://github.com/mongodb/node-mongodb-native/issues/2843)) ([e4a9a57](https://github.com/mongodb/node-mongodb-native/commit/e4a9a572427666fd1a89576dadf50b9c452e1659))
12+
* **NODE-3358:** Command monitoring objects hold internal state references ([#2858](https://github.com/mongodb/node-mongodb-native/issues/2858)) ([750760c](https://github.com/mongodb/node-mongodb-native/commit/750760c324ddedb72491befde9f7aff1ceec009c))
13+
* **NODE-3380:** perform retryable write checks against server ([#2861](https://github.com/mongodb/node-mongodb-native/issues/2861)) ([621677a](https://github.com/mongodb/node-mongodb-native/commit/621677a42772e0b26aa13883f57d7e42f86df43f))
14+
* **NODE-3397:** report more helpful error with unsupported authMechanism in initial handshake ([#2876](https://github.com/mongodb/node-mongodb-native/issues/2876)) ([3ce148d](https://github.com/mongodb/node-mongodb-native/commit/3ce148d8fb37faea1ee056f6e9331e5282e65cd0))
15+
516
### [3.6.9](https://github.com/mongodb/node-mongodb-native/compare/v3.6.8...v3.6.9) (2021-05-26)
617

718

lib/cmap/connection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ function write(command, options, callback) {
344344
promoteLongs: typeof options.promoteLongs === 'boolean' ? options.promoteLongs : true,
345345
promoteValues: typeof options.promoteValues === 'boolean' ? options.promoteValues : true,
346346
promoteBuffers: typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : false,
347+
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false,
347348
raw: typeof options.raw === 'boolean' ? options.raw : false
348349
};
349350

lib/collection.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ function Collection(db, topology, dbName, name, pkFactory, options) {
120120
options == null || options.promoteBuffers == null
121121
? db.s.options.promoteBuffers
122122
: options.promoteBuffers;
123+
const bsonRegExp =
124+
options == null || options.bsonRegExp == null ? db.s.options.bsonRegExp : options.bsonRegExp;
123125
const collectionHint = null;
124126

125127
const namespace = new MongoDBNamespace(dbName, name);
@@ -156,6 +158,8 @@ function Collection(db, topology, dbName, name, pkFactory, options) {
156158
promoteValues: promoteValues,
157159
// promoteBuffers
158160
promoteBuffers: promoteBuffers,
161+
// bsonRegExp
162+
bsonRegExp: bsonRegExp,
159163
// internalHint
160164
internalHint: internalHint,
161165
// collectionHint
@@ -303,6 +307,7 @@ const DEPRECATED_FIND_OPTIONS = ['maxScan', 'fields', 'snapshot', 'oplogReplay']
303307
* @param {boolean} [options.promoteLongs=true] Promotes Long values to number if they fit inside the 53 bits resolution.
304308
* @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types.
305309
* @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers.
310+
* @param {boolean} [options.bsonRegExp=false] By default, regex returned from MDB will be native to the language. Setting to true will ensure that a BSON.BSONRegExp object is returned.
306311
* @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
307312
* @param {boolean} [options.partial=false] Specify if the cursor should return partial results when querying against a sharded system
308313
* @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
@@ -451,6 +456,8 @@ Collection.prototype.find = deprecateOptions(
451456
newOptions.promoteValues = this.s.promoteValues;
452457
if (newOptions.promoteBuffers == null && typeof this.s.promoteBuffers === 'boolean')
453458
newOptions.promoteBuffers = this.s.promoteBuffers;
459+
if (newOptions.bsonRegExp == null && typeof this.s.bsonRegExp === 'boolean')
460+
newOptions.bsonRegExp = this.s.bsonRegExp;
454461

455462
// Sort options
456463
if (findCommand.sort) {
@@ -1075,6 +1082,7 @@ Collection.prototype.save = deprecate(function(doc, options, callback) {
10751082
* @param {boolean} [options.promoteLongs=true] Promotes Long values to number if they fit inside the 53 bits resolution.
10761083
* @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types.
10771084
* @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers.
1085+
* @param {boolean} [options.bsonRegExp=false] By default, regex returned from MDB will be native to the language. Setting to true will ensure that a BSON.BSONRegExp object is returned.
10781086
* @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
10791087
* @param {boolean} [options.partial=false] Specify if the cursor should return partial results when querying against a sharded system
10801088
* @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
@@ -1899,6 +1907,7 @@ Collection.prototype.findAndRemove = deprecate(function(query, sort, options, ca
18991907
* @param {boolean} [options.promoteLongs=true] Promotes Long values to number if they fit inside the 53 bits resolution.
19001908
* @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types.
19011909
* @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers.
1910+
* @param {boolean} [options.bsonRegExp=false] By default, regex returned from MDB will be native to the language. Setting to true will ensure that a BSON.BSONRegExp object is returned.
19021911
* @param {object} [options.collation] Specify collation settings for operation. See {@link https://docs.mongodb.com/manual/reference/command/aggregate|aggregation documentation}.
19031912
* @param {string} [options.comment] Add a comment to an aggregation command
19041913
* @param {string|object} [options.hint] Add an index selection hint to an aggregation command

lib/command_utils.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const Msg = require('./core/connection/msg').Msg;
33
const KillCursor = require('./core/connection/commands').KillCursor;
44
const GetMore = require('./core/connection/commands').GetMore;
5+
const deepCopy = require('./utils').deepCopy;
56

67
/** Commands that we want to redact because of the sensitive nature of their contents */
78
const SENSITIVE_COMMANDS = new Set([
@@ -63,17 +64,17 @@ const extractCommand = command => {
6364
let extractedCommand;
6465
if (command instanceof GetMore) {
6566
extractedCommand = {
66-
getMore: command.cursorId,
67+
getMore: deepCopy(command.cursorId),
6768
collection: collectionName(command),
6869
batchSize: command.numberToReturn
6970
};
7071
} else if (command instanceof KillCursor) {
7172
extractedCommand = {
7273
killCursors: collectionName(command),
73-
cursors: command.cursorIds
74+
cursors: deepCopy(command.cursorIds)
7475
};
7576
} else if (command instanceof Msg) {
76-
extractedCommand = command.command;
77+
extractedCommand = deepCopy(command.command);
7778
} else if (command.query && command.query.$query) {
7879
let result;
7980
if (command.ns === 'admin.$cmd') {
@@ -84,12 +85,13 @@ const extractCommand = command => {
8485
result = { find: collectionName(command) };
8586
Object.keys(LEGACY_FIND_QUERY_MAP).forEach(key => {
8687
if (typeof command.query[key] !== 'undefined')
87-
result[LEGACY_FIND_QUERY_MAP[key]] = command.query[key];
88+
result[LEGACY_FIND_QUERY_MAP[key]] = deepCopy(command.query[key]);
8889
});
8990
}
9091

9192
Object.keys(LEGACY_FIND_OPTIONS_MAP).forEach(key => {
92-
if (typeof command[key] !== 'undefined') result[LEGACY_FIND_OPTIONS_MAP[key]] = command[key];
93+
if (typeof command[key] !== 'undefined')
94+
result[LEGACY_FIND_OPTIONS_MAP[key]] = deepCopy(command[key]);
9395
});
9496

9597
OP_QUERY_KEYS.forEach(key => {
@@ -106,7 +108,7 @@ const extractCommand = command => {
106108
extractedCommand = result;
107109
}
108110
} else {
109-
extractedCommand = command.query || command;
111+
extractedCommand = deepCopy(command.query || command);
110112
}
111113

112114
const commandName = Object.keys(extractedCommand)[0];

lib/core/connection/commands.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,12 @@ KillCursor.prototype.toBin = function() {
398398
};
399399

400400
var Response = function(bson, message, msgHeader, msgBody, opts) {
401-
opts = opts || { promoteLongs: true, promoteValues: true, promoteBuffers: false };
401+
opts = opts || {
402+
promoteLongs: true,
403+
promoteValues: true,
404+
promoteBuffers: false,
405+
bsonRegExp: false
406+
};
402407
this.parsed = false;
403408
this.raw = message;
404409
this.data = msgBody;
@@ -429,6 +434,7 @@ var Response = function(bson, message, msgHeader, msgBody, opts) {
429434
this.promoteLongs = typeof opts.promoteLongs === 'boolean' ? opts.promoteLongs : true;
430435
this.promoteValues = typeof opts.promoteValues === 'boolean' ? opts.promoteValues : true;
431436
this.promoteBuffers = typeof opts.promoteBuffers === 'boolean' ? opts.promoteBuffers : false;
437+
this.bsonRegExp = typeof opts.bsonRegExp === 'boolean' ? opts.bsonRegExp : false;
432438
};
433439

434440
Response.prototype.isParsed = function() {
@@ -449,13 +455,16 @@ Response.prototype.parse = function(options) {
449455
typeof options.promoteValues === 'boolean' ? options.promoteValues : this.opts.promoteValues;
450456
var promoteBuffers =
451457
typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : this.opts.promoteBuffers;
458+
var bsonRegExp =
459+
typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : this.opts.bsonRegExp;
452460
var bsonSize, _options;
453461

454462
// Set up the options
455463
_options = {
456464
promoteLongs: promoteLongs,
457465
promoteValues: promoteValues,
458-
promoteBuffers: promoteBuffers
466+
promoteBuffers: promoteBuffers,
467+
bsonRegExp: bsonRegExp
459468
};
460469

461470
// Position within OP_REPLY at which documents start

lib/core/connection/connect.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ function prepareHandshakeDocument(authContext, callback) {
185185
}
186186

187187
const authProvider = AUTH_PROVIDERS[credentials.mechanism];
188+
if (authProvider == null) {
189+
return callback(new MongoError(`No AuthProvider for ${credentials.mechanism} defined.`));
190+
}
188191
authProvider.prepare(handshakeDoc, authContext, callback);
189192
return;
190193
}

lib/core/connection/connection.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const DEBUG_FIELDS = [
3838
'promoteLongs',
3939
'promoteValues',
4040
'promoteBuffers',
41+
'bsonRegExp',
4142
'checkServerIdentity'
4243
];
4344

@@ -73,6 +74,7 @@ class Connection extends EventEmitter {
7374
* @param {boolean} [options.promoteLongs] Convert Long values from the db into Numbers if they fit into 53 bits
7475
* @param {boolean} [options.promoteValues] Promotes BSON values to native types where possible, set to false to only receive wrapper types.
7576
* @param {boolean} [options.promoteBuffers] Promotes Binary BSON values to native Node Buffers.
77+
* @param {boolean} [options.bsonRegExp] By default, regex returned from MDB will be native to the language. Setting to true will ensure that a BSON.BSONRegExp object is returned.
7678
* @param {number} [options.maxBsonMessageSize=0x4000000] Largest possible size of a BSON message (for legacy purposes)
7779
*/
7880
constructor(socket, options) {
@@ -117,7 +119,8 @@ class Connection extends EventEmitter {
117119
this.responseOptions = {
118120
promoteLongs: typeof options.promoteLongs === 'boolean' ? options.promoteLongs : true,
119121
promoteValues: typeof options.promoteValues === 'boolean' ? options.promoteValues : true,
120-
promoteBuffers: typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : false
122+
promoteBuffers: typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : false,
123+
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false
121124
};
122125

123126
// Flushing

lib/core/connection/msg.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ Msg.getRequestId = function() {
139139

140140
class BinMsg {
141141
constructor(bson, message, msgHeader, msgBody, opts) {
142-
opts = opts || { promoteLongs: true, promoteValues: true, promoteBuffers: false };
142+
opts = opts || {
143+
promoteLongs: true,
144+
promoteValues: true,
145+
promoteBuffers: false,
146+
bsonRegExp: false
147+
};
143148
this.parsed = false;
144149
this.raw = message;
145150
this.data = msgBody;
@@ -161,6 +166,7 @@ class BinMsg {
161166
this.promoteLongs = typeof opts.promoteLongs === 'boolean' ? opts.promoteLongs : true;
162167
this.promoteValues = typeof opts.promoteValues === 'boolean' ? opts.promoteValues : true;
163168
this.promoteBuffers = typeof opts.promoteBuffers === 'boolean' ? opts.promoteBuffers : false;
169+
this.bsonRegExp = typeof opts.bsonRegExp === 'boolean' ? opts.bsonRegExp : false;
164170

165171
this.documents = [];
166172
}
@@ -186,12 +192,15 @@ class BinMsg {
186192
typeof options.promoteBuffers === 'boolean'
187193
? options.promoteBuffers
188194
: this.opts.promoteBuffers;
195+
const bsonRegExp =
196+
typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : this.opts.bsonRegExp;
189197

190198
// Set up the options
191199
const _options = {
192200
promoteLongs: promoteLongs,
193201
promoteValues: promoteValues,
194-
promoteBuffers: promoteBuffers
202+
promoteBuffers: promoteBuffers,
203+
bsonRegExp: bsonRegExp
195204
};
196205

197206
while (this.index < this.data.length) {

lib/core/connection/pool.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ var _id = 0;
7676
* @param {boolean} [options.promoteLongs=true] Convert Long values from the db into Numbers if they fit into 53 bits
7777
* @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types.
7878
* @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers.
79+
* @param {boolean} [options.bsonRegExp=false] By default, regex returned from MDB will be native to the language. Setting to true will ensure that a BSON.BSONRegExp object is returned.
7980
* @param {boolean} [options.domainsEnabled=false] Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit.
8081
* @fires Pool#connect
8182
* @fires Pool#close
@@ -127,6 +128,7 @@ var Pool = function(topology, options) {
127128
promoteLongs: true,
128129
promoteValues: true,
129130
promoteBuffers: false,
131+
bsonRegExp: false,
130132
// Reconnection options
131133
reconnect: true,
132134
reconnectInterval: 1000,
@@ -870,6 +872,7 @@ Pool.prototype.write = function(command, options, cb) {
870872
promoteLongs: true,
871873
promoteValues: true,
872874
promoteBuffers: false,
875+
bsonRegExp: false,
873876
fullResult: false
874877
};
875878

@@ -879,6 +882,7 @@ Pool.prototype.write = function(command, options, cb) {
879882
typeof options.promoteValues === 'boolean' ? options.promoteValues : true;
880883
operation.promoteBuffers =
881884
typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : false;
885+
operation.bsonRegExp = typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false;
882886
operation.raw = typeof options.raw === 'boolean' ? options.raw : false;
883887
operation.immediateRelease =
884888
typeof options.immediateRelease === 'boolean' ? options.immediateRelease : false;

lib/core/cursor.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ class CoreCursor extends Readable {
146146
this.cursorState.promoteBuffers = options.promoteBuffers;
147147
}
148148

149+
// Add bsonRegExp to cursor state
150+
if (typeof topologyOptions.bsonRegExp === 'boolean') {
151+
this.cursorState.bsonRegExp = topologyOptions.bsonRegExp;
152+
} else if (typeof options.bsonRegExp === 'boolean') {
153+
this.cursorState.bsonRegExp = options.bsonRegExp;
154+
}
155+
149156
if (topologyOptions.reconnect) {
150157
this.cursorState.reconnect = topologyOptions.reconnect;
151158
}

0 commit comments

Comments
 (0)