mongodb 3.3.1 → 3.3.2

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 CHANGED
@@ -2,6 +2,18 @@
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.2"></a>
6
+ ## [3.3.2](https://github.com/mongodb/node-mongodb-native/compare/v3.3.1...v3.3.2) (2019-08-28)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **change-stream:** default to server default batch size ([b3ae4c5](https://github.com/mongodb/node-mongodb-native/commit/b3ae4c5))
12
+ * **execute-operation:** return promise on session support check ([a976c14](https://github.com/mongodb/node-mongodb-native/commit/a976c14))
13
+ * **gridfs-stream:** ensure `close` is emitted after last chunk ([ae94cb9](https://github.com/mongodb/node-mongodb-native/commit/ae94cb9))
14
+
15
+
16
+
5
17
  <a name="3.3.1"></a>
6
18
  ## [3.3.1](https://github.com/mongodb/node-mongodb-native/compare/v3.3.0...v3.3.1) (2019-08-23)
7
19
 
@@ -367,10 +367,9 @@ function createChangeStreamCursor(self, options) {
367
367
 
368
368
  const pipeline = [{ $changeStream: changeStreamStageOptions }].concat(self.pipeline);
369
369
  const cursorOptions = applyKnownOptions({}, options, CURSOR_OPTIONS);
370
- const changeStreamOptions = Object.assign({ batchSize: 1 }, options);
371
370
  const changeStreamCursor = new ChangeStreamCursor(
372
371
  self.topology,
373
- new AggregateOperation(self.parent, pipeline, changeStreamOptions),
372
+ new AggregateOperation(self.parent, pipeline, options),
374
373
  cursorOptions
375
374
  );
376
375
 
@@ -139,7 +139,7 @@ class Topology extends EventEmitter {
139
139
  // Server Session Pool
140
140
  sessionPool: null,
141
141
  // Active client sessions
142
- sessions: [],
142
+ sessions: new Set(),
143
143
  // Promise library
144
144
  promiseLibrary: options.promiseLibrary || Promise,
145
145
  credentials: options.credentials,
@@ -421,10 +421,10 @@ class Topology extends EventEmitter {
421
421
  startSession(options, clientOptions) {
422
422
  const session = new ClientSession(this, this.s.sessionPool, options, clientOptions);
423
423
  session.once('ended', () => {
424
- this.s.sessions = this.s.sessions.filter(s => !s.equals(session));
424
+ this.s.sessions.delete(session);
425
425
  });
426
426
 
427
- this.s.sessions.push(session);
427
+ this.s.sessions.add(session);
428
428
  return session;
429
429
  }
430
430
 
@@ -185,12 +185,19 @@ function doRead(_this) {
185
185
  }
186
186
  if (!doc) {
187
187
  _this.push(null);
188
- return _this.s.cursor.close(function(error) {
189
- if (error) {
190
- return __handleError(_this, error);
191
- }
192
- _this.emit('close');
188
+
189
+ process.nextTick(() => {
190
+ _this.s.cursor.close(function(error) {
191
+ if (error) {
192
+ __handleError(_this, error);
193
+ return;
194
+ }
195
+
196
+ _this.emit('close');
197
+ });
193
198
  });
199
+
200
+ return;
194
201
  }
195
202
 
196
203
  var bytesRemaining = _this.s.file.length - _this.s.bytesRead;
@@ -157,7 +157,7 @@ function MongoClient(url, options) {
157
157
  options: options || {},
158
158
  promiseLibrary: null,
159
159
  dbCache: new Map(),
160
- sessions: [],
160
+ sessions: new Set(),
161
161
  writeConcern: WriteConcern.fromOptions(options),
162
162
  namespace: new MongoDBNamespace('admin')
163
163
  };
@@ -242,7 +242,7 @@ function collectEvents(mongoClient, topology) {
242
242
  }
243
243
 
244
244
  const emitDeprecationForNonUnifiedTopology = deprecate(() => {},
245
- 'current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. ' + 'To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to MongoClient.connect.');
245
+ 'current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. ' + 'To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.');
246
246
 
247
247
  function connect(mongoClient, url, options, callback) {
248
248
  options = Object.assign({}, options);
@@ -35,18 +35,7 @@ function executeOperation(topology, operation, callback) {
35
35
  !operation.hasAspect(Aspect.SKIP_SESSION) &&
36
36
  topology.shouldCheckForSessionSupport()
37
37
  ) {
38
- // TODO: this is only supported for unified topology, the first part of this check
39
- // should go away when we drop legacy topology types.
40
- topology.selectServer(ReadPreference.primaryPreferred, err => {
41
- if (err) {
42
- callback(err);
43
- return;
44
- }
45
-
46
- executeOperation(topology, operation, callback);
47
- });
48
-
49
- return;
38
+ return selectServerForSessionSupport(topology, operation, callback);
50
39
  }
51
40
 
52
41
  const Promise = topology.s.promiseLibrary;
@@ -179,4 +168,31 @@ function executeWithServerSelection(topology, operation, callback) {
179
168
  });
180
169
  }
181
170
 
171
+ // TODO: This is only supported for unified topology, it should go away once
172
+ // we remove support for legacy topology types.
173
+ function selectServerForSessionSupport(topology, operation, callback) {
174
+ const Promise = topology.s.promiseLibrary;
175
+
176
+ let result;
177
+ if (typeof callback !== 'function') {
178
+ result = new Promise((resolve, reject) => {
179
+ callback = (err, result) => {
180
+ if (err) return reject(err);
181
+ resolve(result);
182
+ };
183
+ });
184
+ }
185
+
186
+ topology.selectServer(ReadPreference.primaryPreferred, err => {
187
+ if (err) {
188
+ callback(err);
189
+ return;
190
+ }
191
+
192
+ executeOperation(topology, operation, callback);
193
+ });
194
+
195
+ return result;
196
+ }
197
+
182
198
  module.exports = executeOperation;
@@ -194,7 +194,7 @@ class Mongos extends TopologyBase {
194
194
  // Server Session Pool
195
195
  sessionPool: null,
196
196
  // Active client sessions
197
- sessions: [],
197
+ sessions: new Set(),
198
198
  // Promise library
199
199
  promiseLibrary: options.promiseLibrary || Promise
200
200
  };
@@ -210,7 +210,7 @@ class ReplSet extends TopologyBase {
210
210
  // Server Session Pool
211
211
  sessionPool: null,
212
212
  // Active client sessions
213
- sessions: [],
213
+ sessions: new Set(),
214
214
  // Promise library
215
215
  promiseLibrary: options.promiseLibrary || Promise
216
216
  };
@@ -202,7 +202,7 @@ class Server extends TopologyBase {
202
202
  // Server Session Pool
203
203
  sessionPool: null,
204
204
  // Active client sessions
205
- sessions: [],
205
+ sessions: new Set(),
206
206
  // Promise library
207
207
  promiseLibrary: promiseLibrary || Promise
208
208
  };
@@ -291,11 +291,12 @@ class TopologyBase extends EventEmitter {
291
291
 
292
292
  startSession(options, clientOptions) {
293
293
  const session = new ClientSession(this, this.s.sessionPool, options, clientOptions);
294
+
294
295
  session.once('ended', () => {
295
- this.s.sessions = this.s.sessions.filter(s => !s.equals(session));
296
+ this.s.sessions.delete(session);
296
297
  });
297
298
 
298
- this.s.sessions.push(session);
299
+ this.s.sessions.add(session);
299
300
  return session;
300
301
  }
301
302
 
@@ -382,9 +383,7 @@ class TopologyBase extends EventEmitter {
382
383
  close(forceClosed, callback) {
383
384
  // If we have sessions, we want to individually move them to the session pool,
384
385
  // and then send a single endSessions call.
385
- if (this.s.sessions.length) {
386
- this.s.sessions.forEach(session => session.endSession());
387
- }
386
+ this.s.sessions.forEach(session => session.endSession());
388
387
 
389
388
  if (this.s.sessionPool) {
390
389
  this.s.sessionPool.endAllPooledSessions();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb",
3
- "version": "3.3.1",
3
+ "version": "3.3.2",
4
4
  "description": "The official MongoDB driver for Node.js",
5
5
  "main": "index.js",
6
6
  "files": [