mongodb 3.2.0-beta1 → 3.2.3

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,74 @@
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.3"></a>
6
+ ## [3.2.3](https://github.com/mongodb/node-mongodb-native/compare/v3.2.2...v3.2.3) (2019-04-05)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **aggregation:** fix field name typo ([4235d04](https://github.com/mongodb/node-mongodb-native/commit/4235d04))
12
+ * **async:** rewrote asyncGenerator in node < 10 syntax ([49c8cef](https://github.com/mongodb/node-mongodb-native/commit/49c8cef))
13
+ * **bulkWrite:** fix issue with bulkWrite continuing w/ callback ([2a4a42c](https://github.com/mongodb/node-mongodb-native/commit/2a4a42c))
14
+ * **docs:** correctly document that default for `sslValidate` is false ([1f8e7fa](https://github.com/mongodb/node-mongodb-native/commit/1f8e7fa))
15
+
16
+
17
+ ### Features
18
+
19
+ * update to mongodb-core v3.2.3 ([1c5357a](https://github.com/mongodb/node-mongodb-native/commit/1c5357a))
20
+
21
+
22
+
23
+ <a name="3.2.2"></a>
24
+ ## [3.2.2](https://github.com/mongodb/node-mongodb-native/compare/v3.2.1...v3.2.2) (2019-03-22)
25
+
26
+
27
+ ### Bug Fixes
28
+
29
+ * **asyncIterator:** stronger guard against importing async generator ([e0826fb](https://github.com/mongodb/node-mongodb-native/commit/e0826fb))
30
+
31
+
32
+ ### Features
33
+
34
+ * update to mongodb-core v3.2.2 ([868cfc3](https://github.com/mongodb/node-mongodb-native/commit/868cfc3))
35
+
36
+
37
+
38
+ <a name="3.2.1"></a>
39
+ ## [3.2.1](https://github.com/mongodb/node-mongodb-native/compare/v3.2.0...v3.2.1) (2019-03-21)
40
+
41
+
42
+ ### Features
43
+
44
+ * **core:** update to mongodb-core v3.2.1 ([30b0100](https://github.com/mongodb/node-mongodb-native/commit/30b0100))
45
+
46
+
47
+
48
+ <a name="3.2.0"></a>
49
+ # [3.2.0](https://github.com/mongodb/node-mongodb-native/compare/v3.1.13...v3.2.0) (2019-03-21)
50
+
51
+
52
+ ### Bug Fixes
53
+
54
+ * **aggregate:** do not send batchSize for aggregation with $out ([ddb8d90](https://github.com/mongodb/node-mongodb-native/commit/ddb8d90))
55
+ * **bulkWrite:** always count undefined values in bson size for bulk ([436d340](https://github.com/mongodb/node-mongodb-native/commit/436d340))
56
+ * **db_ops:** rename db to add user on ([79931af](https://github.com/mongodb/node-mongodb-native/commit/79931af))
57
+ * **mongo_client_ops:** only skip authentication if no authMechanism is specified ([3b6957d](https://github.com/mongodb/node-mongodb-native/commit/3b6957d))
58
+ * **mongo-client:** ensure close callback is called with client ([f39e881](https://github.com/mongodb/node-mongodb-native/commit/f39e881))
59
+
60
+
61
+ ### Features
62
+
63
+ * **core:** pin to mongodb-core v3.2.0 ([22af15a](https://github.com/mongodb/node-mongodb-native/commit/22af15a))
64
+ * **Cursor:** adds support for AsyncIterator in cursors ([b972c1e](https://github.com/mongodb/node-mongodb-native/commit/b972c1e))
65
+ * **db:** add database-level aggregation ([b629b21](https://github.com/mongodb/node-mongodb-native/commit/b629b21))
66
+ * **mongo-client:** remove deprecated `logout` and print warning ([542859d](https://github.com/mongodb/node-mongodb-native/commit/542859d))
67
+ * **topology-base:** support passing callbacks to `close` method ([7c111e0](https://github.com/mongodb/node-mongodb-native/commit/7c111e0))
68
+ * **transactions:** support pinning mongos for sharded txns ([3886127](https://github.com/mongodb/node-mongodb-native/commit/3886127))
69
+ * **unified-sdam:** backport unified SDAM to master for v3.2.0 ([79f33ca](https://github.com/mongodb/node-mongodb-native/commit/79f33ca))
70
+
71
+
72
+
5
73
  <a name="3.1.13"></a>
6
74
  ## [3.1.13](https://github.com/mongodb/node-mongodb-native/compare/v3.1.12...v3.1.13) (2019-01-23)
7
75
 
@@ -222,6 +290,19 @@ All notable changes to this project will be documented in this file. See [standa
222
290
 
223
291
 
224
292
 
293
+ <a name="3.1.1"></a>
294
+ ## [3.1.1](https://github.com/mongodb/node-mongodb-native/compare/v3.1.0...v3.1.1) (2018-07-05)
295
+
296
+
297
+ ### Bug Fixes
298
+
299
+ * **client-ops:** return transform map to map rather than function ([b8b4bfa](https://github.com/mongodb/node-mongodb-native/commit/b8b4bfa))
300
+ * **collection:** correctly shallow clone passed in options ([2e6c4fa](https://github.com/mongodb/node-mongodb-native/commit/2e6c4fa))
301
+ * **collection:** countDocuments throws error when query doesn't match docs ([4e83556](https://github.com/mongodb/node-mongodb-native/commit/4e83556))
302
+ * **server:** remove unnecessary print statement ([20e11b3](https://github.com/mongodb/node-mongodb-native/commit/20e11b3))
303
+
304
+
305
+
225
306
  <a name="3.1.0"></a>
226
307
  # [3.1.0](https://github.com/mongodb/node-mongodb-native/compare/v3.0.6...v3.1.0) (2018-06-27)
227
308
 
package/README.md CHANGED
@@ -40,6 +40,13 @@ Core Server (i.e. SERVER) project are **public**.
40
40
 
41
41
  Change history can be found in [`HISTORY.md`](HISTORY.md).
42
42
 
43
+ ### Compatibility
44
+
45
+ For version compatibility matrices, please refer to the following links:
46
+
47
+ * [MongoDB](https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/#reference-compatibility-mongodb-node)
48
+ * [NodeJS](https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/#reference-compatibility-language-node)
49
+
43
50
  # Installation
44
51
 
45
52
  The recommended way to get started using the Node.js 3.0 driver is by using the `npm` (Node Package Manager) to install the dependency in your project.
@@ -5,6 +5,7 @@ const MongoError = require('mongodb-core').MongoError;
5
5
  const Readable = require('stream').Readable;
6
6
  const CoreCursor = require('./cursor');
7
7
  const deprecate = require('util').deprecate;
8
+ const SUPPORTS = require('./utils').SUPPORTS;
8
9
 
9
10
  /**
10
11
  * @fileOverview The **AggregationCursor** class is an internal class that embodies an aggregation cursor on MongoDB
@@ -130,6 +131,11 @@ inherits(AggregationCursor, Readable);
130
131
  for (var name in CoreCursor.prototype) {
131
132
  AggregationCursor.prototype[name] = CoreCursor.prototype[name];
132
133
  }
134
+ if (SUPPORTS.ASYNC_ITERATOR) {
135
+ AggregationCursor.prototype[
136
+ Symbol.asyncIterator
137
+ ] = require('./async/async_iterator').asyncIterator;
138
+ }
133
139
 
134
140
  /**
135
141
  * Set the batch size for the cursor.
@@ -142,7 +148,7 @@ AggregationCursor.prototype.batchSize = function(value) {
142
148
  if (this.s.state === AggregationCursor.CLOSED || this.isDead())
143
149
  throw MongoError.create({ message: 'Cursor is closed', driver: true });
144
150
  if (typeof value !== 'number')
145
- throw MongoError.create({ message: 'batchSize requires an integer', drvier: true });
151
+ throw MongoError.create({ message: 'batchSize requires an integer', driver: true });
146
152
  if (this.s.cmd.cursor) this.s.cmd.cursor.batchSize = value;
147
153
  this.setCursorBatchSize(value);
148
154
  return this;
@@ -320,7 +326,7 @@ AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
320
326
  /**
321
327
  * Returns an array of documents. The caller is responsible for making sure that there
322
328
  * is enough memory to store the results. Note that the array only contain partial
323
- * results when this cursor had been previouly accessed. In that case,
329
+ * results when this cursor had been previously accessed. In that case,
324
330
  * cursor.rewind() can be used to reset the cursor.
325
331
  * @method AggregationCursor.prototype.toArray
326
332
  * @param {AggregationCursor~toArrayResultCallback} [callback] The result callback.
@@ -337,7 +343,7 @@ AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
337
343
 
338
344
  /**
339
345
  * Iterates over all the documents for this cursor. As with **{cursor.toArray}**,
340
- * not all of the elements will be iterated if this cursor had been previouly accessed.
346
+ * not all of the elements will be iterated if this cursor had been previously accessed.
341
347
  * In that case, **{cursor.rewind}** can be used to reset the cursor. However, unlike
342
348
  * **{cursor.toArray}**, the cursor will only hold a maximum of batch size elements
343
349
  * at any given time if batch size is specified. Otherwise, the caller is responsible
@@ -0,0 +1,5 @@
1
+ {
2
+ "parserOptions": {
3
+ "ecmaVersion": 2018
4
+ }
5
+ }
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ // async function* asyncIterator() {
4
+ // while (true) {
5
+ // const value = await this.next();
6
+ // if (!value) {
7
+ // await this.close();
8
+ // return;
9
+ // }
10
+
11
+ // yield value;
12
+ // }
13
+ // }
14
+
15
+ // TODO: change this to the async generator function above
16
+ function asyncIterator() {
17
+ const cursor = this;
18
+
19
+ return {
20
+ next: function() {
21
+ return Promise.resolve()
22
+ .then(() => cursor.next())
23
+ .then(value => {
24
+ if (!value) {
25
+ return cursor.close().then(() => ({ value, done: true }));
26
+ }
27
+ return { value, done: false };
28
+ });
29
+ }
30
+ };
31
+ }
32
+
33
+ exports.asyncIterator = asyncIterator;
@@ -55,7 +55,7 @@ class Batch {
55
55
  }
56
56
 
57
57
  /**
58
- * Wraps a legacy operation so we can correctly rewrite it's error
58
+ * Wraps a legacy operation so we can correctly rewrite its error
59
59
  * @ignore
60
60
  */
61
61
  class LegacyOp {
@@ -906,6 +906,15 @@ class BulkOperationBase {
906
906
  );
907
907
  }
908
908
 
909
+ _handleEarlyError(err, callback) {
910
+ if (typeof callback === 'function') {
911
+ callback(err, null);
912
+ return;
913
+ }
914
+
915
+ return this.s.promiseLibrary.reject(err);
916
+ }
917
+
909
918
  /**
910
919
  * Execute next write command in a chain
911
920
  *
@@ -919,19 +928,17 @@ class BulkOperationBase {
919
928
  if (typeof options === 'function') (callback = options), (options = {});
920
929
  options = options || {};
921
930
 
922
- if (this.s.executed) {
923
- const executedError = toError('batch cannot be re-executed');
924
- return typeof callback === 'function'
925
- ? callback(executedError, null)
926
- : this.s.promiseLibrary.reject(executedError);
927
- }
928
-
929
931
  if (typeof _writeConcern === 'function') {
930
932
  callback = _writeConcern;
931
933
  } else if (_writeConcern && typeof _writeConcern === 'object') {
932
934
  this.s.writeConcern = _writeConcern;
933
935
  }
934
936
 
937
+ if (this.s.executed) {
938
+ const executedError = toError('batch cannot be re-executed');
939
+ return this._handleEarlyError(executedError, callback);
940
+ }
941
+
935
942
  // If we have current batch
936
943
  if (this.isOrdered) {
937
944
  if (this.s.currentBatch) this.s.batches.push(this.s.currentBatch);
@@ -943,9 +950,7 @@ class BulkOperationBase {
943
950
  // If we have no operations in the bulk raise an error
944
951
  if (this.s.batches.length === 0) {
945
952
  const emptyBatchError = toError('Invalid Operation, no operations specified');
946
- return typeof callback === 'function'
947
- ? callback(emptyBatchError, null)
948
- : this.s.promiseLibrary.reject(emptyBatchError);
953
+ return this._handleEarlyError(emptyBatchError, callback);
949
954
  }
950
955
  return { options, callback };
951
956
  }
@@ -25,7 +25,11 @@ const isPromiseLike = require('../utils').isPromiseLike;
25
25
  function addToOperationsList(bulkOperation, docType, document) {
26
26
  // Get the bsonSize
27
27
  const bsonSize = bson.calculateObjectSize(document, {
28
- checkKeys: false
28
+ checkKeys: false,
29
+
30
+ // Since we don't know what the user selected for BSON options here,
31
+ // err on the safe side, and check the size with ignoreUndefined: false.
32
+ ignoreUndefined: false
29
33
  });
30
34
 
31
35
  // Throw error if the doc is bigger than the max BSON size
@@ -115,7 +119,7 @@ class OrderedBulkOperation extends BulkOperationBase {
115
119
  */
116
120
  execute(_writeConcern, options, callback) {
117
121
  const ret = this.bulkExecute(_writeConcern, options, callback);
118
- if (isPromiseLike(ret)) {
122
+ if (!ret || isPromiseLike(ret)) {
119
123
  return ret;
120
124
  }
121
125
 
@@ -25,7 +25,11 @@ const isPromiseLike = require('../utils').isPromiseLike;
25
25
  function addToOperationsList(bulkOperation, docType, document) {
26
26
  // Get the bsonSize
27
27
  const bsonSize = bson.calculateObjectSize(document, {
28
- checkKeys: false
28
+ checkKeys: false,
29
+
30
+ // Since we don't know what the user selected for BSON options here,
31
+ // err on the safe side, and check the size with ignoreUndefined: false.
32
+ ignoreUndefined: false
29
33
  });
30
34
  // Throw error if the doc is bigger than the max BSON size
31
35
  if (bsonSize >= bulkOperation.s.maxBatchSizeBytes)
@@ -127,7 +131,7 @@ class UnorderedBulkOperation extends BulkOperationBase {
127
131
  */
128
132
  execute(_writeConcern, options, callback) {
129
133
  const ret = this.bulkExecute(_writeConcern, options, callback);
130
- if (isPromiseLike(ret)) {
134
+ if (!ret || isPromiseLike(ret)) {
131
135
  return ret;
132
136
  }
133
137
 
package/lib/collection.js CHANGED
@@ -45,12 +45,12 @@ const group = require('./operations/collection_ops').group;
45
45
  const indexes = require('./operations/collection_ops').indexes;
46
46
  const indexExists = require('./operations/collection_ops').indexExists;
47
47
  const indexInformation = require('./operations/collection_ops').indexInformation;
48
+ const insertMany = require('./operations/collection_ops').insertMany;
48
49
  const insertOne = require('./operations/collection_ops').insertOne;
49
50
  const isCapped = require('./operations/collection_ops').isCapped;
50
51
  const mapReduce = require('./operations/collection_ops').mapReduce;
51
52
  const optionsOp = require('./operations/collection_ops').optionsOp;
52
53
  const parallelCollectionScan = require('./operations/collection_ops').parallelCollectionScan;
53
- const prepareDocs = require('./operations/collection_ops').prepareDocs;
54
54
  const reIndex = require('./operations/collection_ops').reIndex;
55
55
  const removeDocuments = require('./operations/collection_ops').removeDocuments;
56
56
  const rename = require('./operations/collection_ops').rename;
@@ -268,7 +268,7 @@ const DEPRECATED_FIND_OPTIONS = ['maxScan', 'fields', 'snapshot'];
268
268
  * @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers.
269
269
  * @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
270
270
  * @param {boolean} [options.partial=false] Specify if the cursor should return partial results when querying against a sharded system
271
- * @param {number} [options.maxTimeMS] Number of miliseconds to wait before aborting the query.
271
+ * @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
272
272
  * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
273
273
  * @param {ClientSession} [options.session] optional session to use for this operation
274
274
  * @throws {MongoError}
@@ -454,7 +454,7 @@ Collection.prototype.insertOne = function(doc, options, callback) {
454
454
  if (typeof options === 'function') (callback = options), (options = {});
455
455
  options = options || {};
456
456
 
457
- // Add ignoreUndfined
457
+ // Add ignoreUndefined
458
458
  if (this.s.options.ignoreUndefined) {
459
459
  options = Object.assign({}, options);
460
460
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -463,21 +463,6 @@ Collection.prototype.insertOne = function(doc, options, callback) {
463
463
  return executeOperation(this.s.topology, insertOne, [this, doc, options, callback]);
464
464
  };
465
465
 
466
- function mapInsertManyResults(docs, r) {
467
- const finalResult = {
468
- result: { ok: 1, n: r.insertedCount },
469
- ops: docs,
470
- insertedCount: r.insertedCount,
471
- insertedIds: r.insertedIds
472
- };
473
-
474
- if (r.getLastOp()) {
475
- finalResult.result.opTime = r.getLastOp();
476
- }
477
-
478
- return finalResult;
479
- }
480
-
481
466
  /**
482
467
  * Inserts an array of documents into MongoDB. If documents passed in do not contain the **_id** field,
483
468
  * one will be added to each of the documents missing it by the driver, mutating the document. This behavior
@@ -501,33 +486,7 @@ Collection.prototype.insertMany = function(docs, options, callback) {
501
486
  if (typeof options === 'function') (callback = options), (options = {});
502
487
  options = options ? Object.assign({}, options) : { ordered: true };
503
488
 
504
- if (!Array.isArray(docs) && typeof callback === 'function') {
505
- return callback(
506
- MongoError.create({ message: 'docs parameter must be an array of documents', driver: true })
507
- );
508
- } else if (!Array.isArray(docs)) {
509
- return new this.s.promiseLibrary((resolve, reject) => {
510
- reject(
511
- MongoError.create({ message: 'docs parameter must be an array of documents', driver: true })
512
- );
513
- });
514
- }
515
-
516
- // If keep going set unordered
517
- options['serializeFunctions'] = options['serializeFunctions'] || this.s.serializeFunctions;
518
-
519
- docs = prepareDocs(this, docs, options);
520
-
521
- // Generate the bulk write operations
522
- const operations = [
523
- {
524
- insertMany: docs
525
- }
526
- ];
527
-
528
- return executeOperation(this.s.topology, bulkWrite, [this, operations, options, callback], {
529
- resultMutator: result => mapInsertManyResults(docs, result)
530
- });
489
+ return executeOperation(this.s.topology, insertMany, [this, docs, options, callback]);
531
490
  };
532
491
 
533
492
  /**
@@ -726,7 +685,7 @@ Collection.prototype.updateOne = function(filter, update, options, callback) {
726
685
 
727
686
  options = Object.assign({}, options);
728
687
 
729
- // Add ignoreUndfined
688
+ // Add ignoreUndefined
730
689
  if (this.s.options.ignoreUndefined) {
731
690
  options = Object.assign({}, options);
732
691
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -754,7 +713,7 @@ Collection.prototype.replaceOne = function(filter, doc, options, callback) {
754
713
  if (typeof options === 'function') (callback = options), (options = {});
755
714
  options = Object.assign({}, options);
756
715
 
757
- // Add ignoreUndfined
716
+ // Add ignoreUndefined
758
717
  if (this.s.options.ignoreUndefined) {
759
718
  options = Object.assign({}, options);
760
719
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -790,7 +749,7 @@ Collection.prototype.updateMany = function(filter, update, options, callback) {
790
749
 
791
750
  options = Object.assign({}, options);
792
751
 
793
- // Add ignoreUndfined
752
+ // Add ignoreUndefined
794
753
  if (this.s.options.ignoreUndefined) {
795
754
  options = Object.assign({}, options);
796
755
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -823,7 +782,7 @@ Collection.prototype.update = deprecate(function(selector, update, options, call
823
782
  if (typeof options === 'function') (callback = options), (options = {});
824
783
  options = options || {};
825
784
 
826
- // Add ignoreUndfined
785
+ // Add ignoreUndefined
827
786
  if (this.s.options.ignoreUndefined) {
828
787
  options = Object.assign({}, options);
829
788
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -870,7 +829,7 @@ Collection.prototype.deleteOne = function(filter, options, callback) {
870
829
  if (typeof options === 'function') (callback = options), (options = {});
871
830
  options = Object.assign({}, options);
872
831
 
873
- // Add ignoreUndfined
832
+ // Add ignoreUndefined
874
833
  if (this.s.options.ignoreUndefined) {
875
834
  options = Object.assign({}, options);
876
835
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -897,7 +856,7 @@ Collection.prototype.deleteMany = function(filter, options, callback) {
897
856
  if (typeof options === 'function') (callback = options), (options = {});
898
857
  options = Object.assign({}, options);
899
858
 
900
- // Add ignoreUndfined
859
+ // Add ignoreUndefined
901
860
  if (this.s.options.ignoreUndefined) {
902
861
  options = Object.assign({}, options);
903
862
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -926,7 +885,7 @@ Collection.prototype.remove = deprecate(function(selector, options, callback) {
926
885
  if (typeof options === 'function') (callback = options), (options = {});
927
886
  options = options || {};
928
887
 
929
- // Add ignoreUndfined
888
+ // Add ignoreUndefined
930
889
  if (this.s.options.ignoreUndefined) {
931
890
  options = Object.assign({}, options);
932
891
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -953,7 +912,7 @@ Collection.prototype.save = deprecate(function(doc, options, callback) {
953
912
  if (typeof options === 'function') (callback = options), (options = {});
954
913
  options = options || {};
955
914
 
956
- // Add ignoreUndfined
915
+ // Add ignoreUndefined
957
916
  if (this.s.options.ignoreUndefined) {
958
917
  options = Object.assign({}, options);
959
918
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -1004,7 +963,7 @@ Collection.prototype.save = deprecate(function(doc, options, callback) {
1004
963
  * @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers.
1005
964
  * @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
1006
965
  * @param {boolean} [options.partial=false] Specify if the cursor should return partial results when querying against a sharded system
1007
- * @param {number} [options.maxTimeMS] Number of miliseconds to wait before aborting the query.
966
+ * @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
1008
967
  * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
1009
968
  * @param {ClientSession} [options.session] optional session to use for this operation
1010
969
  * @param {Collection~resultCallback} [callback] The command result callback
@@ -1167,7 +1126,7 @@ Collection.prototype.createIndexes = function(indexSpecs, options, callback) {
1167
1126
  * @param {number} [options.wtimeout] The write concern timeout.
1168
1127
  * @param {boolean} [options.j=false] Specify a journal write concern.
1169
1128
  * @param {ClientSession} [options.session] optional session to use for this operation
1170
- * @param {number} [options.maxTimeMS] Number of miliseconds to wait before aborting the query.
1129
+ * @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
1171
1130
  * @param {Collection~resultCallback} [callback] The command result callback
1172
1131
  * @return {Promise} returns Promise if no callback passed
1173
1132
  */
@@ -1187,7 +1146,7 @@ Collection.prototype.dropIndex = function(indexName, options, callback) {
1187
1146
  * @method
1188
1147
  * @param {Object} [options] Optional settings
1189
1148
  * @param {ClientSession} [options.session] optional session to use for this operation
1190
- * @param {number} [options.maxTimeMS] Number of miliseconds to wait before aborting the query.
1149
+ * @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
1191
1150
  * @param {Collection~resultCallback} [callback] The command result callback
1192
1151
  * @return {Promise} returns Promise if no callback passed
1193
1152
  */
@@ -1359,7 +1318,7 @@ Collection.prototype.indexInformation = function(options, callback) {
1359
1318
  * @param {boolean} [options.skip] The number of documents to skip for the count.
1360
1319
  * @param {string} [options.hint] An index name hint for the query.
1361
1320
  * @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
1362
- * @param {number} [options.maxTimeMS] Number of miliseconds to wait before aborting the query.
1321
+ * @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
1363
1322
  * @param {ClientSession} [options.session] optional session to use for this operation
1364
1323
  * @param {Collection~countCallback} [callback] The command result callback
1365
1324
  * @return {Promise} returns Promise if no callback passed
@@ -1439,7 +1398,7 @@ Collection.prototype.countDocuments = function(query, options, callback) {
1439
1398
  * @param {object} query The query for filtering the set of documents to which we apply the distinct filter.
1440
1399
  * @param {object} [options] Optional settings.
1441
1400
  * @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
1442
- * @param {number} [options.maxTimeMS] Number of miliseconds to wait before aborting the query.
1401
+ * @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
1443
1402
  * @param {ClientSession} [options.session] optional session to use for this operation
1444
1403
  * @param {Collection~resultCallback} [callback] The command result callback
1445
1404
  * @return {Promise} returns Promise if no callback passed
@@ -5,6 +5,7 @@ const ReadPreference = require('mongodb-core').ReadPreference;
5
5
  const MongoError = require('mongodb-core').MongoError;
6
6
  const Readable = require('stream').Readable;
7
7
  const CoreCursor = require('./cursor');
8
+ const SUPPORTS = require('./utils').SUPPORTS;
8
9
 
9
10
  /**
10
11
  * @fileOverview The **CommandCursor** class is an internal class that embodies a
@@ -156,6 +157,10 @@ for (var i = 0; i < methodsToInherit.length; i++) {
156
157
  CommandCursor.prototype[methodsToInherit[i]] = CoreCursor.prototype[methodsToInherit[i]];
157
158
  }
158
159
 
160
+ if (SUPPORTS.ASYNC_ITERATOR) {
161
+ CommandCursor.prototype[Symbol.asyncIterator] = require('./async/async_iterator').asyncIterator;
162
+ }
163
+
159
164
  /**
160
165
  * Set the ReadPreference for the cursor.
161
166
  * @method
@@ -254,7 +259,7 @@ CommandCursor.prototype.get = CommandCursor.prototype.toArray;
254
259
  /**
255
260
  * Returns an array of documents. The caller is responsible for making sure that there
256
261
  * is enough memory to store the results. Note that the array only contain partial
257
- * results when this cursor had been previouly accessed.
262
+ * results when this cursor had been previously accessed.
258
263
  * @method CommandCursor.prototype.toArray
259
264
  * @param {CommandCursor~toArrayResultCallback} [callback] The result callback.
260
265
  * @throws {MongoError}
@@ -270,7 +275,7 @@ CommandCursor.prototype.get = CommandCursor.prototype.toArray;
270
275
 
271
276
  /**
272
277
  * Iterates over all the documents for this cursor. As with **{cursor.toArray}**,
273
- * not all of the elements will be iterated if this cursor had been previouly accessed.
278
+ * not all of the elements will be iterated if this cursor had been previously accessed.
274
279
  * In that case, **{cursor.rewind}** can be used to reset the cursor. However, unlike
275
280
  * **{cursor.toArray}**, the cursor will only hold a maximum of batch size elements
276
281
  * at any given time if batch size is specified. Otherwise, the caller is responsible
package/lib/cursor.js CHANGED
@@ -5,6 +5,7 @@ const PassThrough = require('stream').PassThrough;
5
5
  const inherits = require('util').inherits;
6
6
  const deprecate = require('util').deprecate;
7
7
  const handleCallback = require('./utils').handleCallback;
8
+ const SUPPORTS = require('./utils').SUPPORTS;
8
9
  const ReadPreference = require('mongodb-core').ReadPreference;
9
10
  const MongoError = require('mongodb-core').MongoError;
10
11
  const Readable = require('stream').Readable;
@@ -203,6 +204,10 @@ function Cursor(bson, ns, cmd, options, topology, topologyOptions) {
203
204
  // Inherit from Readable
204
205
  inherits(Cursor, Readable);
205
206
 
207
+ if (SUPPORTS.ASYNC_ITERATOR) {
208
+ Cursor.prototype[Symbol.asyncIterator] = require('./async/async_iterator').asyncIterator;
209
+ }
210
+
206
211
  // Map core cursor _next method so we can apply mapping
207
212
  Cursor.prototype._next = function() {
208
213
  if (this._initImplicitSession) {
@@ -688,7 +693,7 @@ Cursor.prototype.skip = function(value) {
688
693
 
689
694
  /**
690
695
  * Iterates over all the documents for this cursor. As with **{cursor.toArray}**,
691
- * not all of the elements will be iterated if this cursor had been previouly accessed.
696
+ * not all of the elements will be iterated if this cursor had been previously accessed.
692
697
  * In that case, **{cursor.rewind}** can be used to reset the cursor. However, unlike
693
698
  * **{cursor.toArray}**, the cursor will only hold a maximum of batch size elements
694
699
  * at any given time if batch size is specified. Otherwise, the caller is responsible
@@ -806,7 +811,7 @@ Cursor.prototype.setReadPreference = function(readPreference) {
806
811
  /**
807
812
  * Returns an array of documents. The caller is responsible for making sure that there
808
813
  * is enough memory to store the results. Note that the array only contains partial
809
- * results when this cursor had been previouly accessed. In that case,
814
+ * results when this cursor had been previously accessed. In that case,
810
815
  * cursor.rewind() can be used to reset the cursor.
811
816
  * @method
812
817
  * @param {Cursor~toArrayResultCallback} [callback] The result callback.
@@ -840,7 +845,7 @@ Cursor.prototype.toArray = function(callback) {
840
845
  * @param {object} [options] Optional settings.
841
846
  * @param {number} [options.skip] The number of documents to skip.
842
847
  * @param {number} [options.limit] The maximum amounts to count before aborting.
843
- * @param {number} [options.maxTimeMS] Number of miliseconds to wait before aborting the query.
848
+ * @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
844
849
  * @param {string} [options.hint] An index name hint for the query.
845
850
  * @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
846
851
  * @param {Cursor~countResultCallback} [callback] The result callback.
package/lib/db.js CHANGED
@@ -113,7 +113,7 @@ const legalOptionNames = [
113
113
  * @param {object} [options.pkFactory] A primary key factory object for generation of custom _id keys.
114
114
  * @param {object} [options.promiseLibrary] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
115
115
  * @param {object} [options.readConcern] Specify a read concern for the collection. (only MongoDB 3.2 or higher supported)
116
- * @param {object} [options.readConcern.level='local'] Specify a read concern level for the collection operations, one of [local|majority]. (only MongoDB 3.2 or higher supported)
116
+ * @param {ReadConcernLevel} [options.readConcern.level='local'] Specify a read concern level for the collection operations (only MongoDB 3.2 or higher supported)
117
117
  * @property {(Server|ReplSet|Mongos)} serverConfig Get the current db topology.
118
118
  * @property {number} bufferMaxEntries Current bufferMaxEntries value for the database
119
119
  * @property {string} databaseName The name of the database this instance represents.
@@ -355,7 +355,7 @@ const collectionKeys = [
355
355
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
356
356
  * @param {boolean} [options.strict=false] Returns an error if the collection does not exist
357
357
  * @param {object} [options.readConcern] Specify a read concern for the collection. (only MongoDB 3.2 or higher supported)
358
- * @param {object} [options.readConcern.level='local'] Specify a read concern level for the collection operations, one of [local|majority]. (only MongoDB 3.2 or higher supported)
358
+ * @param {ReadConcernLevel} [options.readConcern.level='local'] Specify a read concern level for the collection operations (only MongoDB 3.2 or higher supported)
359
359
  * @param {Db~collectionResultCallback} [callback] The collection result callback
360
360
  * @return {Collection} return the new Collection instance if not in strict mode
361
361
  */
@@ -595,7 +595,7 @@ Db.prototype.listCollections = function(filter, options) {
595
595
  * @param {Code} code JavaScript to execute on server.
596
596
  * @param {(object|array)} parameters The parameters for the call.
597
597
  * @param {object} [options] Optional settings.
598
- * @param {boolean} [options.nolock=false] Tell MongoDB not to block on the evaulation of the javascript.
598
+ * @param {boolean} [options.nolock=false] Tell MongoDB not to block on the evaluation of the javascript.
599
599
  * @param {ClientSession} [options.session] optional session to use for this operation
600
600
  * @param {Db~resultCallback} [callback] The results callback
601
601
  * @deprecated Eval is deprecated on MongoDB 3.2 and forward
@@ -867,7 +867,7 @@ Db.prototype.setProfilingLevel = function(level, options, callback) {
867
867
  };
868
868
 
869
869
  /**
870
- * Retrive the current profiling information for MongoDB
870
+ * Retrieve the current profiling information for MongoDB
871
871
  *
872
872
  * @param {Object} [options] Optional settings
873
873
  * @param {ClientSession} [options.session] optional session to use for this operation
@@ -65,7 +65,7 @@ const deprecationFn = deprecate(() => {},
65
65
  *
66
66
  * Modes
67
67
  * - **"r"** - read only. This is the default mode.
68
- * - **"w"** - write in truncate mode. Existing data will be overwriten.
68
+ * - **"w"** - write in truncate mode. Existing data will be overwritten.
69
69
  *
70
70
  * @class
71
71
  * @param {Db} db A database instance to interact with.
@@ -4,7 +4,6 @@ const ChangeStream = require('./change_stream');
4
4
  const Db = require('./db');
5
5
  const EventEmitter = require('events').EventEmitter;
6
6
  const executeOperation = require('./utils').executeOperation;
7
- const handleCallback = require('./utils').handleCallback;
8
7
  const inherits = require('util').inherits;
9
8
  const MongoError = require('mongodb-core').MongoError;
10
9
  const deprecate = require('util').deprecate;
@@ -12,6 +11,7 @@ const deprecate = require('util').deprecate;
12
11
  // Operations
13
12
  const connectOp = require('./operations/mongo_client_ops').connectOp;
14
13
  const validOptions = require('./operations/mongo_client_ops').validOptions;
14
+ const closeOperation = require('./operations/mongo_client_ops').closeOperation;
15
15
 
16
16
  /**
17
17
  * @fileOverview The **MongoClient** class is a class that allows for making Connections to MongoDB.
@@ -46,6 +46,12 @@ const validOptions = require('./operations/mongo_client_ops').validOptions;
46
46
  * });
47
47
  */
48
48
 
49
+ /**
50
+ * A string specifying the level of a ReadConcern
51
+ * @typedef {'local'|'available'|'majority'|'linearizable'|'snapshot'} ReadConcernLevel
52
+ * @see https://docs.mongodb.com/manual/reference/read-concern/index.html#read-concern-levels
53
+ */
54
+
49
55
  /**
50
56
  * Creates a new MongoClient instance
51
57
  * @class
@@ -53,7 +59,7 @@ const validOptions = require('./operations/mongo_client_ops').validOptions;
53
59
  * @param {object} [options] Optional settings
54
60
  * @param {number} [options.poolSize=5] The maximum size of the individual server pool
55
61
  * @param {boolean} [options.ssl=false] Enable SSL connection.
56
- * @param {boolean} [options.sslValidate=true] Validate mongod server certificate against Certificate Authority
62
+ * @param {boolean} [options.sslValidate=false] Validate mongod server certificate against Certificate Authority
57
63
  * @param {buffer} [options.sslCA=undefined] SSL Certificate store binary buffer
58
64
  * @param {buffer} [options.sslCert=undefined] SSL Certificate binary buffer
59
65
  * @param {buffer} [options.sslKey=undefined] SSL Key file binary buffer
@@ -88,7 +94,7 @@ const validOptions = require('./operations/mongo_client_ops').validOptions;
88
94
  * @param {object} [options.pkFactory] A primary key factory object for generation of custom _id keys
89
95
  * @param {object} [options.promiseLibrary] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
90
96
  * @param {object} [options.readConcern] Specify a read concern for the collection (only MongoDB 3.2 or higher supported)
91
- * @param {string} [options.readConcern.level='local'] Specify a read concern level for the collection operations, one of [local|majority]. (only MongoDB 3.2 or higher supported)
97
+ * @param {ReadConcernLevel} [options.readConcern.level='local'] Specify a read concern level for the collection operations (only MongoDB 3.2 or higher supported)
92
98
  * @param {number} [options.maxStalenessSeconds=undefined] The max staleness to secondary reads (values under 10 seconds cannot be guaranteed)
93
99
  * @param {string} [options.loggerLevel=undefined] The logging level (error/warn/info/debug)
94
100
  * @param {object} [options.logger=undefined] Custom logger object
@@ -110,6 +116,7 @@ const validOptions = require('./operations/mongo_client_ops').validOptions;
110
116
  * @param {boolean} [options.monitorCommands=false] Enable command monitoring for this client
111
117
  * @param {number} [options.minSize] If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections
112
118
  * @param {boolean} [options.useNewUrlParser=false] Determines whether or not to use the new url parser. Enables the new, spec-compliant, url parser shipped in the core driver. This url parser fixes a number of problems with the original parser, and aims to outright replace that parser in the near future.
119
+ * @param {boolean} [options.useUnifiedTopology] Enables the new unified topology layer
113
120
  * @param {MongoClient~connectCallback} [callback] The command result callback
114
121
  * @return {MongoClient} a MongoClient instance
115
122
  */
@@ -184,31 +191,8 @@ MongoClient.prototype.logout = deprecate(function(options, callback) {
184
191
  */
185
192
  MongoClient.prototype.close = function(force, callback) {
186
193
  if (typeof force === 'function') (callback = force), (force = false);
187
-
188
- // Close the topology connection
189
- if (this.topology) {
190
- this.topology.close(force);
191
- }
192
- // Emit close event
193
- this.emit('close', this);
194
-
195
- // Fire close event on any cached db instances
196
- for (const name in this.s.dbCache) {
197
- this.s.dbCache[name].emit('close');
198
- }
199
-
200
- // Remove listeners after emit
201
- this.removeAllListeners('close');
202
-
203
- // Callback after next event loop tick
204
- if (typeof callback === 'function')
205
- return process.nextTick(() => {
206
- handleCallback(callback, null);
207
- });
208
-
209
- // Return dummy promise
210
- return new this.s.promiseLibrary(resolve => {
211
- resolve();
194
+ return executeOperation(this, closeOperation, [this, force, callback], {
195
+ skipSessions: true
212
196
  });
213
197
  };
214
198
 
@@ -287,7 +271,7 @@ MongoClient.prototype.isConnected = function(options) {
287
271
  * @param {object} [options] Optional settings
288
272
  * @param {number} [options.poolSize=5] The maximum size of the individual server pool
289
273
  * @param {boolean} [options.ssl=false] Enable SSL connection.
290
- * @param {boolean} [options.sslValidate=true] Validate mongod server certificate against Certificate Authority
274
+ * @param {boolean} [options.sslValidate=false] Validate mongod server certificate against Certificate Authority
291
275
  * @param {buffer} [options.sslCA=undefined] SSL Certificate store binary buffer
292
276
  * @param {buffer} [options.sslCert=undefined] SSL Certificate binary buffer
293
277
  * @param {buffer} [options.sslKey=undefined] SSL Key file binary buffer
@@ -322,7 +306,7 @@ MongoClient.prototype.isConnected = function(options) {
322
306
  * @param {object} [options.pkFactory] A primary key factory object for generation of custom _id keys
323
307
  * @param {object} [options.promiseLibrary] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
324
308
  * @param {object} [options.readConcern] Specify a read concern for the collection (only MongoDB 3.2 or higher supported)
325
- * @param {string} [options.readConcern.level='local'] Specify a read concern level for the collection operations, one of [local|majority]. (only MongoDB 3.2 or higher supported)
309
+ * @param {ReadConcernLevel} [options.readConcern.level='local'] Specify a read concern level for the collection operations (only MongoDB 3.2 or higher supported)
326
310
  * @param {number} [options.maxStalenessSeconds=undefined] The max staleness to secondary reads (values under 10 seconds cannot be guaranteed)
327
311
  * @param {string} [options.loggerLevel=undefined] The logging level (error/warn/info/debug)
328
312
  * @param {object} [options.logger=undefined] Custom logger object
@@ -25,13 +25,13 @@ function aggregate(db, coll, pipeline, options, callback) {
25
25
  const isDbAggregate = typeof coll === 'string';
26
26
  const target = isDbAggregate ? db : coll;
27
27
  const topology = target.s.topology;
28
- let ignoreReadConcern = false;
28
+ let hasOutStage = false;
29
29
 
30
30
  if (typeof options.out === 'string') {
31
31
  pipeline = pipeline.concat({ $out: options.out });
32
- ignoreReadConcern = true;
32
+ hasOutStage = true;
33
33
  } else if (pipeline.length > 0 && pipeline[pipeline.length - 1]['$out']) {
34
- ignoreReadConcern = true;
34
+ hasOutStage = true;
35
35
  }
36
36
 
37
37
  let command;
@@ -52,7 +52,7 @@ function aggregate(db, coll, pipeline, options, callback) {
52
52
 
53
53
  const takesWriteConcern = topology.capabilities().commandsTakeWriteConcern;
54
54
 
55
- if (!ignoreReadConcern) {
55
+ if (!hasOutStage) {
56
56
  decorateWithReadConcern(command, target, options);
57
57
  }
58
58
 
@@ -96,7 +96,7 @@ function aggregate(db, coll, pipeline, options, callback) {
96
96
  }
97
97
 
98
98
  options.cursor = options.cursor || {};
99
- if (options.batchSize) options.cursor.batchSize = options.batchSize;
99
+ if (options.batchSize && !hasOutStage) options.cursor.batchSize = options.batchSize;
100
100
  command.cursor = options.cursor;
101
101
 
102
102
  // promiseLibrary
@@ -81,7 +81,7 @@ const groupFunction =
81
81
  * @param {Collection~bulkWriteOpCallback} [callback] The command result callback
82
82
  */
83
83
  function bulkWrite(coll, operations, options, callback) {
84
- // Add ignoreUndfined
84
+ // Add ignoreUndefined
85
85
  if (coll.s.options.ignoreUndefined) {
86
86
  options = Object.assign({}, options);
87
87
  options.ignoreUndefined = coll.s.options.ignoreUndefined;
@@ -225,7 +225,7 @@ function countDocuments(coll, query, options, callback) {
225
225
  pipeline.push({ $limit: limit });
226
226
  }
227
227
 
228
- pipeline.push({ $group: { _id: null, n: { $sum: 1 } } });
228
+ pipeline.push({ $group: { _id: 1, n: { $sum: 1 } } });
229
229
 
230
230
  delete options.limit;
231
231
  delete options.skip;
@@ -892,6 +892,57 @@ function insertOne(coll, doc, options, callback) {
892
892
  });
893
893
  }
894
894
 
895
+ /**
896
+ * Inserts an array of documents into MongoDB. If documents passed in do not contain the **_id** field,
897
+ * one will be added to each of the documents missing it by the driver, mutating the document. This behavior
898
+ * can be overridden by setting the **forceServerObjectId** flag.
899
+ *
900
+ * @method
901
+ * @param {Collection} a Collection instance.
902
+ * @param {object[]} docs Documents to insert.
903
+ * @param {number} [options] Optional settings. See Collection.prototype.insertMany for a list of options.
904
+ * @param {Collection~insertWriteOpCallback} [callback] The command result callback
905
+ */
906
+ function insertMany(coll, docs, options, callback) {
907
+ if (!Array.isArray(docs)) {
908
+ return callback(
909
+ MongoError.create({ message: 'docs parameter must be an array of documents', driver: true })
910
+ );
911
+ }
912
+
913
+ // If keep going set unordered
914
+ options['serializeFunctions'] = options['serializeFunctions'] || coll.s.serializeFunctions;
915
+
916
+ docs = prepareDocs(coll, docs, options);
917
+
918
+ // Generate the bulk write operations
919
+ const operations = [
920
+ {
921
+ insertMany: docs
922
+ }
923
+ ];
924
+
925
+ bulkWrite(coll, operations, options, (err, result) => {
926
+ if (err) return callback(err, null);
927
+ callback(null, mapInsertManyResults(docs, result));
928
+ });
929
+ }
930
+
931
+ function mapInsertManyResults(docs, r) {
932
+ const finalResult = {
933
+ result: { ok: 1, n: r.insertedCount },
934
+ ops: docs,
935
+ insertedCount: r.insertedCount,
936
+ insertedIds: r.insertedIds
937
+ };
938
+
939
+ if (r.getLastOp()) {
940
+ finalResult.result.opTime = r.getLastOp();
941
+ }
942
+
943
+ return finalResult;
944
+ }
945
+
895
946
  /**
896
947
  * Determine whether the collection is a capped collection.
897
948
  *
@@ -1476,6 +1527,7 @@ module.exports = {
1476
1527
  indexes,
1477
1528
  indexExists,
1478
1529
  indexInformation,
1530
+ insertMany,
1479
1531
  insertOne,
1480
1532
  isCapped,
1481
1533
  mapReduce,
@@ -97,10 +97,10 @@ function addUser(db, username, password, options, callback) {
97
97
  const userPassword = md5.digest('hex');
98
98
 
99
99
  // If we have another db set
100
- const db = options.dbName ? new Db(options.dbName, db.s.topology, db.s.options) : db;
100
+ const dbToUse = options.dbName ? new Db(options.dbName, db.s.topology, db.s.options) : db;
101
101
 
102
102
  // Fetch a user collection
103
- const collection = db.collection(CONSTANTS.SYSTEM_USER_COLLECTION);
103
+ const collection = dbToUse.collection(CONSTANTS.SYSTEM_USER_COLLECTION);
104
104
 
105
105
  // Check if we are inserting the first user
106
106
  count(collection, {}, finalOptions, (err, count) => {
@@ -601,7 +601,7 @@ function listCollectionsTransforms(databaseName) {
601
601
  }
602
602
 
603
603
  /**
604
- * Retrive the current profiling information for MongoDB
604
+ * Retrieve the current profiling information for MongoDB
605
605
  *
606
606
  * @method
607
607
  * @param {Db} db The Db instance on which to retrieve the profiling info.
@@ -111,7 +111,8 @@ const validOptionNames = [
111
111
  'retryWrites',
112
112
  'useNewUrlParser',
113
113
  'useUnifiedTopology',
114
- 'serverSelectionTimeoutMS'
114
+ 'serverSelectionTimeoutMS',
115
+ 'useRecoveryToken'
115
116
  ];
116
117
 
117
118
  function addListeners(mongoClient, topology) {
@@ -593,10 +594,12 @@ function validOptions(options) {
593
594
  continue;
594
595
  }
595
596
 
596
- if (_validOptions.indexOf(name) === -1 && options.validateOptions) {
597
- return new MongoError(`option ${name} is not supported`);
598
- } else if (_validOptions.indexOf(name) === -1) {
599
- console.warn(`the options [${name}] is not supported`);
597
+ if (_validOptions.indexOf(name) === -1) {
598
+ if (options.validateOptions) {
599
+ return new MongoError(`option ${name} is not supported`);
600
+ } else {
601
+ console.warn(`the options [${name}] is not supported`);
602
+ }
600
603
  }
601
604
 
602
605
  if (legacyOptionNames.indexOf(name) !== -1) {
@@ -631,7 +634,7 @@ function generateCredentials(client, username, password, options) {
631
634
  options = Object.assign({}, options);
632
635
 
633
636
  // the default db to authenticate against is 'self'
634
- // if authententicate is called from a retry context, it may be another one, like admin
637
+ // if authenticate is called from a retry context, it may be another one, like admin
635
638
  const source = options.authSource || options.authdb || options.dbName;
636
639
 
637
640
  // authMechanism
@@ -663,4 +666,23 @@ function generateCredentials(client, username, password, options) {
663
666
  });
664
667
  }
665
668
 
666
- module.exports = { connectOp, validOptions };
669
+ function closeOperation(client, force, callback) {
670
+ const completeClose = err => {
671
+ client.emit('close', client);
672
+ for (const name in client.s.dbCache) {
673
+ client.s.dbCache[name].emit('close', client);
674
+ }
675
+
676
+ client.removeAllListeners('close');
677
+ callback(err, null);
678
+ };
679
+
680
+ if (client.topology == null) {
681
+ completeClose();
682
+ return;
683
+ }
684
+
685
+ client.topology.close(force, completeClose);
686
+ }
687
+
688
+ module.exports = { connectOp, validOptions, closeOperation };
@@ -70,7 +70,7 @@ var legalOptionNames = [
70
70
  * @param {number} [options.acceptableLatencyMS=15] Cutoff latency point in MS for MongoS proxy selection
71
71
  * @param {boolean} [options.ssl=false] Use ssl connection (needs to have a mongod server with ssl support)
72
72
  * @param {boolean|function} [options.checkServerIdentity=true] Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function.
73
- * @param {boolean} [options.sslValidate=true] Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher)
73
+ * @param {boolean} [options.sslValidate=false] Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher)
74
74
  * @param {array} [options.sslCA] Array of valid certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher)
75
75
  * @param {array} [options.sslCRL] Array of revocation certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher)
76
76
  * @param {string} [options.ciphers] Passed directly through to tls.createSecureContext. See https://nodejs.org/dist/latest-v9.x/docs/api/tls.html#tls_tls_createsecurecontext_options for more info.
@@ -80,7 +80,7 @@ var legalOptionNames = [
80
80
  * @param {number} [options.poolSize=5] Number of connections in the connection pool for each server instance, set to 5 as default for legacy reasons.
81
81
  * @param {boolean} [options.ssl=false] Use ssl connection (needs to have a mongod server with ssl support)
82
82
  * @param {boolean|function} [options.checkServerIdentity=true] Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function.
83
- * @param {boolean} [options.sslValidate=true] Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher)
83
+ * @param {boolean} [options.sslValidate=false] Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher)
84
84
  * @param {array} [options.sslCA] Array of valid certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher)
85
85
  * @param {array} [options.sslCRL] Array of revocation certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher)
86
86
  * @param {(Buffer|string)} [options.sslCert] String or buffer containing the certificate we wish to present (needs to have a mongod server with ssl support, 2.4 or higher.
@@ -381,10 +381,9 @@ class ReplSet extends TopologyBase {
381
381
  self.s.coreTopology.connect(_options);
382
382
  }
383
383
 
384
- close(forceClosed) {
385
- super.close(forceClosed);
386
-
384
+ close(forceClosed, callback) {
387
385
  ['timeout', 'error', 'close', 'joined', 'left'].forEach(e => this.removeAllListeners(e));
386
+ super.close(forceClosed, callback);
388
387
  }
389
388
  }
390
389
 
@@ -70,7 +70,7 @@ var legalOptionNames = [
70
70
  * @param {object} [options] Optional settings.
71
71
  * @param {number} [options.poolSize=5] Number of connections in the connection pool for each server instance, set to 5 as default for legacy reasons.
72
72
  * @param {boolean} [options.ssl=false] Use ssl connection (needs to have a mongod server with ssl support)
73
- * @param {boolean} [options.sslValidate=true] Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher)
73
+ * @param {boolean} [options.sslValidate=false] Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher)
74
74
  * @param {boolean|function} [options.checkServerIdentity=true] Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function.
75
75
  * @param {array} [options.sslCA] Array of valid certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher)
76
76
  * @param {array} [options.sslCRL] Array of revocation certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher)
@@ -379,7 +379,7 @@ class TopologyBase extends EventEmitter {
379
379
  return this.s.coreTopology.connections();
380
380
  }
381
381
 
382
- close(forceClosed) {
382
+ close(forceClosed, callback) {
383
383
  // If we have sessions, we want to individually move them to the session pool,
384
384
  // and then send a single endSessions call.
385
385
  if (this.s.sessions.length) {
@@ -390,15 +390,18 @@ class TopologyBase extends EventEmitter {
390
390
  this.s.sessionPool.endAllPooledSessions();
391
391
  }
392
392
 
393
- this.s.coreTopology.destroy({
394
- force: typeof forceClosed === 'boolean' ? forceClosed : false
395
- });
396
-
397
393
  // We need to wash out all stored processes
398
394
  if (forceClosed === true) {
399
395
  this.s.storeOptions.force = forceClosed;
400
396
  this.s.store.flush();
401
397
  }
398
+
399
+ this.s.coreTopology.destroy(
400
+ {
401
+ force: typeof forceClosed === 'boolean' ? forceClosed : false
402
+ },
403
+ callback
404
+ );
402
405
  }
403
406
  }
404
407
 
package/lib/url_parser.js CHANGED
@@ -355,7 +355,7 @@ function parseConnectionString(url, options) {
355
355
  if (_host.indexOf('?') !== -1) _host = _host.split(/\?/)[0];
356
356
  }
357
357
 
358
- // No entry returned for duplicate servr
358
+ // No entry returned for duplicate server
359
359
  if (deduplicatedServers[_host + '_' + _port]) return null;
360
360
  deduplicatedServers[_host + '_' + _port] = 1;
361
361
 
package/lib/utils.js CHANGED
@@ -114,7 +114,7 @@ var checkCollectionName = function checkCollectionName(collectionName) {
114
114
  throw new MongoError("collection names must not start or end with '.'");
115
115
  }
116
116
 
117
- // Validate that we are not passing 0x00 in the colletion name
117
+ // Validate that we are not passing 0x00 in the collection name
118
118
  if (collectionName.indexOf('\x00') !== -1) {
119
119
  throw new MongoError('collection names cannot contain a null character');
120
120
  }
@@ -360,7 +360,6 @@ var mergeOptionsAndWriteConcern = function(targetOptions, sourceOptions, keys, m
360
360
  * @param {function} operation The operation to execute
361
361
  * @param {array} args Arguments to apply the provided operation
362
362
  * @param {object} [options] Options that modify the behavior of the method
363
- * @param {function]} [options.resultMutator] Allows for the result of the operation to be changed for custom return types
364
363
  */
365
364
  const executeOperation = (topology, operation, args, options) => {
366
365
  if (topology == null) {
@@ -373,7 +372,6 @@ const executeOperation = (topology, operation, args, options) => {
373
372
 
374
373
  options = options || {};
375
374
  const Promise = topology.s.promiseLibrary;
376
- let resultMutator = options.resultMutator;
377
375
  let callback = args[args.length - 1];
378
376
 
379
377
  // The driver sessions spec mandates that we implicitly create sessions for operations
@@ -397,12 +395,10 @@ const executeOperation = (topology, operation, args, options) => {
397
395
  session.endSession(() => {
398
396
  delete opOptions.session;
399
397
  if (err) return reject(err);
400
- if (resultMutator) return resolve(resultMutator(result));
401
398
  resolve(result);
402
399
  });
403
400
  } else {
404
401
  if (err) return reject(err);
405
- if (resultMutator) return resolve(resultMutator(result));
406
402
  resolve(result);
407
403
  }
408
404
  };
@@ -694,6 +690,15 @@ function deprecateOptions(config, fn) {
694
690
  return deprecated;
695
691
  }
696
692
 
693
+ const SUPPORTS = {};
694
+ // Test asyncIterator support
695
+ try {
696
+ require('./async/async_iterator');
697
+ SUPPORTS.ASYNC_ITERATOR = true;
698
+ } catch (e) {
699
+ SUPPORTS.ASYNC_ITERATOR = false;
700
+ }
701
+
697
702
  module.exports = {
698
703
  filterOptions,
699
704
  mergeOptions,
@@ -719,5 +724,6 @@ module.exports = {
719
724
  isPromiseLike,
720
725
  decorateWithCollation,
721
726
  decorateWithReadConcern,
722
- deprecateOptions
727
+ deprecateOptions,
728
+ SUPPORTS
723
729
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb",
3
- "version": "3.2.0-beta1",
3
+ "version": "3.2.3",
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": "3.2.0-beta1",
20
+ "mongodb-core": "^3.2.3",
21
21
  "safe-buffer": "^5.1.2"
22
22
  },
23
23
  "devDependencies": {