Skip to content

Commit 787f54f

Browse files
committed
Merge branch '3.5' into 3.6
2 parents fc3378c + d7ac176 commit 787f54f

File tree

20 files changed

+518
-92
lines changed

20 files changed

+518
-92
lines changed

HISTORY.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
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+
<a name="3.5.5"></a>
6+
## [3.5.5](https://github.com/mongodb/node-mongodb-native/compare/v3.5.4...v3.5.5) (2020-03-11)
7+
8+
9+
### Bug Fixes
10+
11+
* correctly use template string for connection string error message ([6238c84](https://github.com/mongodb/node-mongodb-native/commit/6238c84))
12+
* don't depend on private node api for `Timeout` wrapper ([3ddaa3e](https://github.com/mongodb/node-mongodb-native/commit/3ddaa3e))
13+
* multiple concurrent attempts to process the queue may fail ([f69f51c](https://github.com/mongodb/node-mongodb-native/commit/f69f51c))
14+
* pass optional promise lib to maybePromise ([cde11ec](https://github.com/mongodb/node-mongodb-native/commit/cde11ec))
15+
* **cursor:** hasNext consumes documents on cursor with limit ([ef04d00](https://github.com/mongodb/node-mongodb-native/commit/ef04d00))
16+
17+
18+
519
<a name="3.5.4"></a>
620
## [3.5.4](https://github.com/mongodb/node-mongodb-native/compare/v3.5.3...v3.5.4) (2020-02-25)
721

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Core Server (i.e. SERVER) project are **public**.
3333

3434
### Support / Feedback
3535

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.
36+
For issues with, questions about, or feedback for the Node.js driver, please look into our [support channels](https://docs.mongodb.com/manual/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 Community Forums](https://community.mongodb.com/tags/c/drivers-odms-connectors/7/node-js-driver).
3737

3838
### Change Log
3939

docs/guide/issues-help.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Issues & Help
44

55
Our developer community is vibrant and highly engaged, with wide experience using Node.js with MongoDB.
66
Often, the quickest way to get support for
7-
general questions is through the `mongodb-user google group <http://groups.google.com/group/mongodb-user>`_
7+
general questions is through the `MongoDB Community Forums <https://community.mongodb.com/tags/c/drivers-odms-connectors/7/node-js-driver>`_
88
or through `stackoverflow <http://stackoverflow.com/questions/tagged/mongodb+nodejs>`_.
99

1010
Refer to our `support channels <http://www.mongodb.org/about/support>`_ documentation for more information.

docs/reference/content/issues-help.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ title = "Issues & Help"
1010

1111
Our developer community is vibrant and highly engaged, with wide experience using Node.js with MongoDB.
1212
Often, the quickest way to get support for
13-
general questions is through the [mongodb-user google group](http://groups.google.com/group/mongodb-user)
13+
general questions is through the [MongoDB Community Forums](https://community.mongodb.com/tags/c/drivers-odms-connectors/7/node-js-driver)
1414
or through [stackoverflow](http://stackoverflow.com/questions/tagged/mongodb+nodejs).
15-
Refer to our [support channels](http://www.mongodb.org/about/support) documentation for more information.
15+
Refer to our [support channels](https://docs.mongodb.com/manual/support) documentation for more information.
1616

1717
## Bugs / Feature Requests
1818

lib/core/sdam/topology.js

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ class Topology extends EventEmitter {
385385
let readPreference;
386386
if (selector instanceof ReadPreference) {
387387
readPreference = selector;
388+
} else if (typeof selector === 'string') {
389+
readPreference = new ReadPreference(selector);
388390
} else {
389391
translateReadPreference(options);
390392
readPreference = options.readPreference || ReadPreference.primary;
@@ -526,10 +528,10 @@ class Topology extends EventEmitter {
526528
}
527529

528530
// If we already know all the information contained in this updated description, then
529-
// we don't need to update anything or emit SDAM events
530-
if (previousServerDescription && previousServerDescription.equals(serverDescription)) {
531-
return;
532-
}
531+
// we don't need to emit SDAM events, but still need to update the description, in order
532+
// to keep client-tracked attributes like last update time and round trip time up to date
533+
const equalDescriptions =
534+
previousServerDescription && previousServerDescription.equals(serverDescription);
533535

534536
// first update the TopologyDescription
535537
this.s.description = this.s.description.update(serverDescription);
@@ -539,15 +541,17 @@ class Topology extends EventEmitter {
539541
}
540542

541543
// emit monitoring events for this change
542-
this.emit(
543-
'serverDescriptionChanged',
544-
new events.ServerDescriptionChangedEvent(
545-
this.s.id,
546-
serverDescription.address,
547-
previousServerDescription,
548-
this.s.description.servers.get(serverDescription.address)
549-
)
550-
);
544+
if (!equalDescriptions) {
545+
this.emit(
546+
'serverDescriptionChanged',
547+
new events.ServerDescriptionChangedEvent(
548+
this.s.id,
549+
serverDescription.address,
550+
previousServerDescription,
551+
this.s.description.servers.get(serverDescription.address)
552+
)
553+
);
554+
}
551555

552556
// update server list from updated descriptions
553557
updateServers(this, serverDescription);
@@ -557,14 +561,16 @@ class Topology extends EventEmitter {
557561
processWaitQueue(this);
558562
}
559563

560-
this.emit(
561-
'topologyDescriptionChanged',
562-
new events.TopologyDescriptionChangedEvent(
563-
this.s.id,
564-
previousTopologyDescription,
565-
this.s.description
566-
)
567-
);
564+
if (!equalDescriptions) {
565+
this.emit(
566+
'topologyDescriptionChanged',
567+
new events.TopologyDescriptionChangedEvent(
568+
this.s.id,
569+
previousTopologyDescription,
570+
this.s.description
571+
)
572+
);
573+
}
568574
}
569575

570576
auth(credentials, callback) {
@@ -1004,10 +1010,9 @@ function processWaitQueue(topology) {
10041010
return;
10051011
}
10061012

1007-
const isSharded = topology.description.type === TopologyType.Sharded;
10081013
const serverDescriptions = Array.from(topology.description.servers.values());
10091014
const membersToProcess = topology[kWaitQueue].length;
1010-
for (let i = 0; i < membersToProcess; ++i) {
1015+
for (let i = 0; i < membersToProcess && topology[kWaitQueue].length; ++i) {
10111016
const waitQueueMember = topology[kWaitQueue].shift();
10121017
if (waitQueueMember[kCancelled]) {
10131018
continue;
@@ -1033,6 +1038,7 @@ function processWaitQueue(topology) {
10331038
const selectedServerDescription = randomSelection(selectedDescriptions);
10341039
const selectedServer = topology.s.servers.get(selectedServerDescription.address);
10351040
const transaction = waitQueueMember.transaction;
1041+
const isSharded = topology.description.type === TopologyType.Sharded;
10361042
if (isSharded && transaction && transaction.isActive) {
10371043
transaction.pinServer(selectedServer);
10381044
}

lib/cursor.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class Cursor extends CoreCursor {
196196
throw MongoError.create({ message: 'Cursor is closed', driver: true });
197197
}
198198

199-
return maybePromise(callback, cb => {
199+
return maybePromise(this, callback, cb => {
200200
const cursor = this;
201201
if (cursor.isNotified()) {
202202
return cb(null, false);
@@ -209,7 +209,13 @@ class Cursor extends CoreCursor {
209209
}
210210

211211
cursor.s.state = CursorState.OPEN;
212+
213+
// NODE-2482: merge this into the core cursor implementation
212214
cursor.cursorState.cursorIndex--;
215+
if (cursor.cursorState.limit > 0) {
216+
cursor.cursorState.currentLimit--;
217+
}
218+
213219
cb(null, true);
214220
});
215221
});
@@ -223,7 +229,7 @@ class Cursor extends CoreCursor {
223229
* @return {Promise} returns Promise if no callback passed
224230
*/
225231
next(callback) {
226-
return maybePromise(callback, cb => {
232+
return maybePromise(this, callback, cb => {
227233
const cursor = this;
228234
if (cursor.s.state === CursorState.CLOSED || (cursor.isDead && cursor.isDead())) {
229235
cb(MongoError.create({ message: 'Cursor is closed', driver: true }));
@@ -812,8 +818,7 @@ class Cursor extends CoreCursor {
812818
driver: true
813819
});
814820
}
815-
816-
return maybePromise(callback, cb => {
821+
return maybePromise(this, callback, cb => {
817822
const cursor = this;
818823
const items = [];
819824

@@ -1040,8 +1045,7 @@ class Cursor extends CoreCursor {
10401045
if (this.cmd.readConcern) {
10411046
delete this.cmd['readConcern'];
10421047
}
1043-
1044-
return maybePromise(callback, cb => {
1048+
return maybePromise(this, callback, cb => {
10451049
CoreCursor.prototype._next.apply(this, [cb]);
10461050
});
10471051
}

lib/mongo_client.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,12 @@ function MongoClient(url, options) {
157157
this.s = {
158158
url: url,
159159
options: options || {},
160-
promiseLibrary: null,
160+
promiseLibrary: (options && options.promiseLibrary) || Promise,
161161
dbCache: new Map(),
162162
sessions: new Set(),
163163
writeConcern: WriteConcern.fromOptions(options),
164164
namespace: new MongoDBNamespace('admin')
165165
};
166-
167-
// Get the promiseLibrary
168-
const promiseLibrary = this.s.options.promiseLibrary || Promise;
169-
170-
// Add the promise to the internal state
171-
this.s.promiseLibrary = promiseLibrary;
172166
}
173167

174168
/**
@@ -214,7 +208,7 @@ MongoClient.prototype.connect = function(callback) {
214208
}
215209

216210
const client = this;
217-
return maybePromise(callback, cb => {
211+
return maybePromise(this, callback, cb => {
218212
const err = validOptions(client.s.options);
219213
if (err) return cb(err);
220214

@@ -244,7 +238,7 @@ MongoClient.prototype.close = function(force, callback) {
244238
}
245239

246240
const client = this;
247-
return maybePromise(callback, cb => {
241+
return maybePromise(this, callback, cb => {
248242
const completeClose = err => {
249243
client.emit('close', client);
250244

lib/utils.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,14 +696,19 @@ function* makeCounter(seed) {
696696
/**
697697
* Helper function for either accepting a callback, or returning a promise
698698
*
699-
* @param {Function} [callback] an optional callback.
699+
* @param {Object} parent an instance of parent with promiseLibrary.
700+
* @param {object} parent.s an object containing promiseLibrary.
701+
* @param {function} parent.s.promiseLibrary an object containing promiseLibrary.
702+
* @param {[Function]} callback an optional callback.
700703
* @param {Function} fn A function that takes a callback
701704
* @returns {Promise|void} Returns nothing if a callback is supplied, else returns a Promise.
702705
*/
703-
function maybePromise(callback, fn) {
706+
function maybePromise(parent, callback, fn) {
707+
const PromiseLibrary = (parent && parent.s && parent.s.promiseLibrary) || Promise;
708+
704709
let result;
705710
if (typeof callback !== 'function') {
706-
result = new Promise((resolve, reject) => {
711+
result = new PromiseLibrary((resolve, reject) => {
707712
callback = (err, res) => {
708713
if (err) return reject(err);
709714
resolve(res);

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mongodb",
3-
"version": "3.5.4",
3+
"version": "3.5.5",
44
"description": "The official MongoDB driver for Node.js",
55
"main": "index.js",
66
"files": [
@@ -31,7 +31,6 @@
3131
"safe-buffer": "^5.1.2"
3232
},
3333
"devDependencies": {
34-
"bluebird": "3.5.0",
3534
"chai": "^4.1.1",
3635
"chai-subset": "^1.6.0",
3736
"chalk": "^2.4.2",

0 commit comments

Comments
 (0)