mongodb 3.6.3 → 3.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/HISTORY.md +63 -1
  2. package/README.md +63 -69
  3. package/lib/admin.js +10 -8
  4. package/lib/aggregation_cursor.js +7 -1
  5. package/lib/bulk/common.js +81 -4
  6. package/lib/cmap/connection.js +36 -32
  7. package/lib/collection.js +151 -89
  8. package/lib/core/auth/mongo_credentials.js +5 -5
  9. package/lib/core/auth/scram.js +2 -1
  10. package/lib/core/connection/connect.js +1 -1
  11. package/lib/core/connection/logger.js +1 -0
  12. package/lib/core/connection/msg.js +3 -1
  13. package/lib/core/connection/utils.js +9 -14
  14. package/lib/core/cursor.js +4 -1
  15. package/lib/core/index.js +1 -1
  16. package/lib/core/sdam/monitor.js +22 -14
  17. package/lib/core/sdam/topology.js +4 -3
  18. package/lib/core/sdam/topology_description.js +24 -6
  19. package/lib/core/tools/smoke_plugin.js +1 -0
  20. package/lib/core/topologies/mongos.js +2 -1
  21. package/lib/core/topologies/read_preference.js +2 -1
  22. package/lib/core/topologies/replset.js +13 -7
  23. package/lib/core/topologies/server.js +3 -2
  24. package/lib/core/uri_parser.js +20 -3
  25. package/lib/core/utils.js +2 -5
  26. package/lib/core/wireprotocol/command.js +10 -5
  27. package/lib/core/wireprotocol/kill_cursors.js +2 -1
  28. package/lib/core/wireprotocol/query.js +12 -11
  29. package/lib/core/wireprotocol/write_command.js +10 -1
  30. package/lib/cursor.js +15 -13
  31. package/lib/db.js +52 -30
  32. package/lib/encrypter.js +163 -0
  33. package/lib/explain.js +55 -0
  34. package/lib/gridfs/grid_store.js +13 -9
  35. package/lib/gridfs-stream/upload.js +6 -3
  36. package/lib/mongo_client.js +123 -170
  37. package/lib/operations/add_user.js +2 -1
  38. package/lib/operations/aggregate.js +5 -7
  39. package/lib/operations/bulk_write.js +0 -8
  40. package/lib/operations/command_v2.js +10 -1
  41. package/lib/operations/common_functions.js +14 -27
  42. package/lib/operations/connect.js +43 -67
  43. package/lib/operations/delete_many.js +15 -2
  44. package/lib/operations/delete_one.js +15 -2
  45. package/lib/operations/distinct.js +10 -2
  46. package/lib/operations/execute_operation.js +47 -69
  47. package/lib/operations/find.js +10 -1
  48. package/lib/operations/find_and_modify.js +14 -1
  49. package/lib/operations/find_one.js +4 -0
  50. package/lib/operations/find_one_and_replace.js +8 -2
  51. package/lib/operations/find_one_and_update.js +8 -3
  52. package/lib/operations/insert_many.js +1 -5
  53. package/lib/operations/map_reduce.js +20 -1
  54. package/lib/operations/operation.js +11 -1
  55. package/lib/operations/update_many.js +23 -2
  56. package/lib/operations/update_one.js +22 -16
  57. package/lib/url_parser.js +19 -14
  58. package/lib/utils.js +110 -32
  59. package/lib/write_concern.js +22 -4
  60. package/package.json +23 -22
package/lib/collection.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const deprecate = require('util').deprecate;
4
4
  const deprecateOptions = require('./utils').deprecateOptions;
5
+ const emitWarningOnce = require('./utils').emitWarningOnce;
5
6
  const checkCollectionName = require('./utils').checkCollectionName;
6
7
  const ObjectID = require('./core').BSON.ObjectID;
7
8
  const MongoError = require('./core').MongoError;
@@ -287,7 +288,6 @@ const DEPRECATED_FIND_OPTIONS = ['maxScan', 'fields', 'snapshot', 'oplogReplay']
287
288
  * @param {object} [options.fields] **Deprecated** Use `options.projection` instead
288
289
  * @param {number} [options.skip=0] Set to skip N documents ahead in your query (useful for pagination).
289
290
  * @param {Object} [options.hint] Tell the query to use specific indexes in the query. Object of indexes to use, {'_id':1}
290
- * @param {boolean} [options.explain=false] Explain the query instead of returning the data.
291
291
  * @param {boolean} [options.snapshot=false] DEPRECATED: Snapshot query.
292
292
  * @param {boolean} [options.timeout=false] Specify if the cursor can timeout.
293
293
  * @param {boolean} [options.tailable=false] Specify if the cursor is tailable.
@@ -310,6 +310,7 @@ const DEPRECATED_FIND_OPTIONS = ['maxScan', 'fields', 'snapshot', 'oplogReplay']
310
310
  * @param {boolean} [options.noCursorTimeout] The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that.
311
311
  * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
312
312
  * @param {boolean} [options.allowDiskUse] Enables writing to temporary files on the server.
313
+ * @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
313
314
  * @param {ClientSession} [options.session] optional session to use for this operation
314
315
  * @throws {MongoError}
315
316
  * @return {Cursor}
@@ -323,7 +324,7 @@ Collection.prototype.find = deprecateOptions(
323
324
  function(query, options, callback) {
324
325
  if (typeof callback === 'object') {
325
326
  // TODO(MAJOR): throw in the future
326
- console.warn('Third parameter to `find()` must be a callback or undefined');
327
+ emitWarningOnce('Third parameter to `find()` must be a callback or undefined');
327
328
  }
328
329
 
329
330
  let selector = query;
@@ -429,7 +430,7 @@ Collection.prototype.find = deprecateOptions(
429
430
  }
430
431
 
431
432
  // Translate to new command option noCursorTimeout
432
- if (typeof newOptions.timeout === 'boolean') newOptions.noCursorTimeout = newOptions.timeout;
433
+ if (typeof newOptions.timeout === 'boolean') newOptions.noCursorTimeout = !newOptions.timeout;
433
434
 
434
435
  decorateCommand(findCommand, newOptions, ['session', 'collation']);
435
436
 
@@ -492,9 +493,10 @@ Collection.prototype.find = deprecateOptions(
492
493
  * @param {object} [options] Optional settings.
493
494
  * @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
494
495
  * @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver.
495
- * @param {(number|string)} [options.w] The write concern.
496
- * @param {number} [options.wtimeout] The write concern timeout.
497
- * @param {boolean} [options.j=false] Specify a journal write concern.
496
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
497
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
498
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
499
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
498
500
  * @param {boolean} [options.checkKeys=true] If true, will throw if bson documents start with `$` or include a `.` in any key value
499
501
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
500
502
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
@@ -528,9 +530,10 @@ Collection.prototype.insertOne = function(doc, options, callback) {
528
530
  * @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
529
531
  * @param {boolean} [options.ordered=true] If true, when an insert fails, don't execute the remaining writes. If false, continue with remaining inserts when one fails.
530
532
  * @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver.
531
- * @param {(number|string)} [options.w] The write concern.
532
- * @param {number} [options.wtimeout] The write concern timeout.
533
- * @param {boolean} [options.j=false] Specify a journal write concern.
533
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
534
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
535
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
536
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
534
537
  * @param {boolean} [options.checkKeys=true] If true, will throw if bson documents start with `$` or include a `.` in any key value
535
538
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
536
539
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
@@ -595,9 +598,10 @@ Collection.prototype.insertMany = function(docs, options, callback) {
595
598
  * @param {boolean} [options.ordered=true] Execute write operation in ordered or unordered fashion.
596
599
  * @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
597
600
  * @param {object[]} [options.arrayFilters] Determines which array elements to modify for update operation in MongoDB 3.6 or higher.
598
- * @param {(number|string)} [options.w] The write concern.
599
- * @param {number} [options.wtimeout] The write concern timeout.
600
- * @param {boolean} [options.j=false] Specify a journal write concern.
601
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
602
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
603
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
604
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
601
605
  * @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
602
606
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
603
607
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
@@ -676,9 +680,10 @@ Collection.prototype.bulkWrite = function(operations, options, callback) {
676
680
  * @method
677
681
  * @param {(object|object[])} docs Documents to insert.
678
682
  * @param {object} [options] Optional settings.
679
- * @param {(number|string)} [options.w] The write concern.
680
- * @param {number} [options.wtimeout] The write concern timeout.
681
- * @param {boolean} [options.j=false] Specify a journal write concern.
683
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
684
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
685
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
686
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
682
687
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
683
688
  * @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver.
684
689
  * @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
@@ -733,12 +738,14 @@ Collection.prototype.insert = deprecate(function(docs, options, callback) {
733
738
  * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
734
739
  * @param {object} [options.hint] An optional hint for query optimization. See the {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-hint|update command} reference for more information.
735
740
  * @param {boolean} [options.upsert=false] When true, creates a new document if no document matches the query..
736
- * @param {(number|string)} [options.w] The write concern.
737
- * @param {number} [options.wtimeout] The write concern timeout.
738
- * @param {boolean} [options.j=false] Specify a journal write concern.
741
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
742
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
743
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
744
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
739
745
  * @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
740
746
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
741
747
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
748
+ * @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
742
749
  * @param {ClientSession} [options.session] optional session to use for this operation
743
750
  * @param {Collection~updateWriteOpCallback} [callback] The command result callback
744
751
  * @return {Promise} returns Promise if no callback passed
@@ -770,9 +777,10 @@ Collection.prototype.updateOne = function(filter, update, options, callback) {
770
777
  * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
771
778
  * @param {object} [options.hint] An optional hint for query optimization. See the {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-hint|update command} reference for more information.
772
779
  * @param {boolean} [options.upsert=false] When true, creates a new document if no document matches the query.
773
- * @param {(number|string)} [options.w] The write concern.
774
- * @param {number} [options.wtimeout] The write concern timeout.
775
- * @param {boolean} [options.j=false] Specify a journal write concern.
780
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
781
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
782
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
783
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
776
784
  * @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
777
785
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
778
786
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
@@ -808,12 +816,14 @@ Collection.prototype.replaceOne = function(filter, doc, options, callback) {
808
816
  * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
809
817
  * @param {object} [options.hint] An optional hint for query optimization. See the {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-hint|update command} reference for more information.
810
818
  * @param {boolean} [options.upsert=false] When true, creates a new document if no document matches the query..
811
- * @param {(number|string)} [options.w] The write concern.
812
- * @param {number} [options.wtimeout] The write concern timeout.
813
- * @param {boolean} [options.j=false] Specify a journal write concern.
819
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
820
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
821
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
822
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
814
823
  * @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
815
824
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
816
825
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
826
+ * @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
817
827
  * @param {ClientSession} [options.session] optional session to use for this operation
818
828
  * @param {Collection~updateWriteOpCallback} [callback] The command result callback
819
829
  * @return {Promise<Collection~updateWriteOpResult>} returns Promise if no callback passed
@@ -841,9 +851,10 @@ Collection.prototype.updateMany = function(filter, update, options, callback) {
841
851
  * @param {object} selector The selector for the update operation.
842
852
  * @param {object} update The update operations to be applied to the documents
843
853
  * @param {object} [options] Optional settings.
844
- * @param {(number|string)} [options.w] The write concern.
845
- * @param {number} [options.wtimeout] The write concern timeout.
846
- * @param {boolean} [options.j=false] Specify a journal write concern.
854
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
855
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
856
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
857
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
847
858
  * @param {boolean} [options.upsert=false] Update operation is an upsert.
848
859
  * @param {boolean} [options.multi=false] Update one/all documents with operation.
849
860
  * @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
@@ -897,12 +908,14 @@ Collection.prototype.update = deprecate(function(selector, update, options, call
897
908
  * @param {object} filter The Filter used to select the document to remove
898
909
  * @param {object} [options] Optional settings.
899
910
  * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
900
- * @param {(number|string)} [options.w] The write concern.
901
- * @param {number} [options.wtimeout] The write concern timeout.
902
- * @param {boolean} [options.j=false] Specify a journal write concern.
911
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
912
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
913
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
914
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
903
915
  * @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
904
916
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
905
917
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
918
+ * @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
906
919
  * @param {ClientSession} [options.session] optional session to use for this operation
907
920
  * @param {string|object} [options.hint] optional index hint for optimizing the filter query
908
921
  * @param {Collection~deleteWriteOpCallback} [callback] The command result callback
@@ -931,12 +944,14 @@ Collection.prototype.removeOne = Collection.prototype.deleteOne;
931
944
  * @param {object} filter The Filter used to select the documents to remove
932
945
  * @param {object} [options] Optional settings.
933
946
  * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
934
- * @param {(number|string)} [options.w] The write concern.
935
- * @param {number} [options.wtimeout] The write concern timeout.
936
- * @param {boolean} [options.j=false] Specify a journal write concern.
947
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
948
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
949
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
950
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
937
951
  * @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
938
952
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
939
953
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
954
+ * @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
940
955
  * @param {ClientSession} [options.session] optional session to use for this operation
941
956
  * @param {string|object} [options.hint] optional index hint for optimizing the filter query
942
957
  * @param {Collection~deleteWriteOpCallback} [callback] The command result callback
@@ -965,9 +980,10 @@ Collection.prototype.removeMany = Collection.prototype.deleteMany;
965
980
  * @param {object} selector The selector for the update operation.
966
981
  * @param {object} [options] Optional settings.
967
982
  * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
968
- * @param {(number|string)} [options.w] The write concern.
969
- * @param {number} [options.wtimeout] The write concern timeout.
970
- * @param {boolean} [options.j=false] Specify a journal write concern.
983
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
984
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
985
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
986
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
971
987
  * @param {boolean} [options.single=false] Removes the first document found.
972
988
  * @param {ClientSession} [options.session] optional session to use for this operation
973
989
  * @param {Collection~writeOpCallback} [callback] The command result callback
@@ -998,9 +1014,10 @@ Collection.prototype.remove = deprecate(function(selector, options, callback) {
998
1014
  * @method
999
1015
  * @param {object} doc Document to save
1000
1016
  * @param {object} [options] Optional settings.
1001
- * @param {(number|string)} [options.w] The write concern.
1002
- * @param {number} [options.wtimeout] The write concern timeout.
1003
- * @param {boolean} [options.j=false] Specify a journal write concern.
1017
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
1018
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
1019
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
1020
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
1004
1021
  * @param {ClientSession} [options.session] optional session to use for this operation
1005
1022
  * @param {Collection~writeOpCallback} [callback] The command result callback
1006
1023
  * @return {Promise} returns Promise if no callback passed
@@ -1044,7 +1061,6 @@ Collection.prototype.save = deprecate(function(doc, options, callback) {
1044
1061
  * @param {object} [options.fields] **Deprecated** Use `options.projection` instead
1045
1062
  * @param {number} [options.skip=0] Set to skip N documents ahead in your query (useful for pagination).
1046
1063
  * @param {Object} [options.hint] Tell the query to use specific indexes in the query. Object of indexes to use, {'_id':1}
1047
- * @param {boolean} [options.explain=false] Explain the query instead of returning the data.
1048
1064
  * @param {boolean} [options.snapshot=false] DEPRECATED: Snapshot query.
1049
1065
  * @param {boolean} [options.timeout=false] Specify if the cursor can timeout.
1050
1066
  * @param {boolean} [options.tailable=false] Specify if the cursor is tailable.
@@ -1063,6 +1079,7 @@ Collection.prototype.save = deprecate(function(doc, options, callback) {
1063
1079
  * @param {boolean} [options.partial=false] Specify if the cursor should return partial results when querying against a sharded system
1064
1080
  * @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
1065
1081
  * @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
1082
+ * @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
1066
1083
  * @param {ClientSession} [options.session] optional session to use for this operation
1067
1084
  * @param {Collection~resultCallback} [callback] The command result callback
1068
1085
  * @return {Promise} returns Promise if no callback passed
@@ -1076,7 +1093,7 @@ Collection.prototype.findOne = deprecateOptions(
1076
1093
  function(query, options, callback) {
1077
1094
  if (typeof callback === 'object') {
1078
1095
  // TODO(MAJOR): throw in the future
1079
- console.warn('Third parameter to `findOne()` must be a callback or undefined');
1096
+ emitWarningOnce('Third parameter to `findOne()` must be a callback or undefined');
1080
1097
  }
1081
1098
 
1082
1099
  if (typeof query === 'function') (callback = query), (query = {}), (options = {});
@@ -1122,10 +1139,10 @@ Collection.prototype.rename = function(newName, options, callback) {
1122
1139
  *
1123
1140
  * @method
1124
1141
  * @param {object} [options] Optional settings.
1125
- * @param {WriteConcern} [options.writeConcern] A full WriteConcern object
1126
- * @param {(number|string)} [options.w] The write concern
1127
- * @param {number} [options.wtimeout] The write concern timeout
1128
- * @param {boolean} [options.j] The journal write concern
1142
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
1143
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
1144
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
1145
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
1129
1146
  * @param {ClientSession} [options.session] optional session to use for this operation
1130
1147
  * @param {Collection~resultCallback} [callback] The results callback
1131
1148
  * @return {Promise} returns Promise if no callback passed
@@ -1184,9 +1201,10 @@ Collection.prototype.isCapped = function(options, callback) {
1184
1201
  * @method
1185
1202
  * @param {(string|array|object)} fieldOrSpec Defines the index.
1186
1203
  * @param {object} [options] Optional settings.
1187
- * @param {(number|string)} [options.w] The write concern.
1188
- * @param {number} [options.wtimeout] The write concern timeout.
1189
- * @param {boolean} [options.j=false] Specify a journal write concern.
1204
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
1205
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
1206
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
1207
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
1190
1208
  * @param {boolean} [options.unique=false] Creates an unique index.
1191
1209
  * @param {boolean} [options.sparse=false] Creates a sparse index.
1192
1210
  * @param {boolean} [options.background=false] Creates the index in the background, yielding whenever possible.
@@ -1297,9 +1315,10 @@ Collection.prototype.createIndexes = function(indexSpecs, options, callback) {
1297
1315
  * @method
1298
1316
  * @param {string} indexName Name of the index to drop.
1299
1317
  * @param {object} [options] Optional settings.
1300
- * @param {(number|string)} [options.w] The write concern.
1301
- * @param {number} [options.wtimeout] The write concern timeout.
1302
- * @param {boolean} [options.j=false] Specify a journal write concern.
1318
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
1319
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
1320
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
1321
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
1303
1322
  * @param {ClientSession} [options.session] optional session to use for this operation
1304
1323
  * @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
1305
1324
  * @param {Collection~resultCallback} [callback] The command result callback
@@ -1395,9 +1414,10 @@ Collection.prototype.listIndexes = function(options) {
1395
1414
  * @deprecated use createIndexes instead
1396
1415
  * @param {(string|object)} fieldOrSpec Defines the index.
1397
1416
  * @param {object} [options] Optional settings.
1398
- * @param {(number|string)} [options.w] The write concern.
1399
- * @param {number} [options.wtimeout] The write concern timeout.
1400
- * @param {boolean} [options.j=false] Specify a journal write concern.
1417
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
1418
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
1419
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
1420
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
1401
1421
  * @param {boolean} [options.unique=false] Creates an unique index.
1402
1422
  * @param {boolean} [options.sparse=false] Creates a sparse index.
1403
1423
  * @param {boolean} [options.background=false] Creates the index in the background, yielding whenever possible.
@@ -1580,6 +1600,7 @@ Collection.prototype.countDocuments = function(query, options, callback) {
1580
1600
  * @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
1581
1601
  * @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
1582
1602
  * @param {object} [options.collation] Specify collation settings for operation. See {@link https://docs.mongodb.com/manual/reference/command/aggregate|aggregation documentation}.
1603
+ * @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
1583
1604
  * @param {ClientSession} [options.session] optional session to use for this operation
1584
1605
  * @param {Collection~resultCallback} [callback] The command result callback
1585
1606
  * @return {Promise} returns Promise if no callback passed
@@ -1634,7 +1655,7 @@ Collection.prototype.stats = function(options, callback) {
1634
1655
 
1635
1656
  /**
1636
1657
  * @typedef {Object} Collection~findAndModifyWriteOpResult
1637
- * @property {object} value Document returned from the `findAndModify` command. If no documents were found, `value` will be `null` by default (`returnOriginal: true`), even if a document was upserted; if `returnOriginal` was false, the upserted document will be returned in that case.
1658
+ * @property {object} value Document returned from the `findAndModify` command. If no documents were found, `value` will be `null` by default even if a document was upserted unless `returnDocument` is specified as `'after'`, in which case the upserted document will be returned.
1638
1659
  * @property {object} lastErrorObject The raw lastErrorObject returned from the command. See {@link https://docs.mongodb.com/manual/reference/command/findAndModify/index.html#lasterrorobject|findAndModify command documentation}.
1639
1660
  * @property {Number} ok Is 1 if the command executed correctly.
1640
1661
  */
@@ -1659,6 +1680,7 @@ Collection.prototype.stats = function(options, callback) {
1659
1680
  * @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
1660
1681
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
1661
1682
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
1683
+ * @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
1662
1684
  * @param {ClientSession} [options.session] optional session to use for this operation
1663
1685
  * @param {Collection~findAndModifyCallback} [callback] The collection result callback
1664
1686
  * @return {Promise<Collection~findAndModifyWriteOpResultObject>} returns Promise if no callback passed
@@ -1667,6 +1689,12 @@ Collection.prototype.findOneAndDelete = function(filter, options, callback) {
1667
1689
  if (typeof options === 'function') (callback = options), (options = {});
1668
1690
  options = options || {};
1669
1691
 
1692
+ // Add ignoreUndefined
1693
+ if (this.s.options.ignoreUndefined) {
1694
+ options = Object.assign({}, options);
1695
+ options.ignoreUndefined = this.s.options.ignoreUndefined;
1696
+ }
1697
+
1670
1698
  return executeOperation(
1671
1699
  this.s.topology,
1672
1700
  new FindOneAndDeleteOperation(this, filter, options),
@@ -1688,24 +1716,39 @@ Collection.prototype.findOneAndDelete = function(filter, options, callback) {
1688
1716
  * @param {object} [options.projection] Limits the fields to return for all matching documents.
1689
1717
  * @param {object} [options.sort] Determines which document the operation modifies if the query selects multiple documents.
1690
1718
  * @param {boolean} [options.upsert=false] Upsert the document if it does not exist.
1691
- * @param {boolean} [options.returnOriginal=true] When false, returns the updated document rather than the original. The default is true.
1719
+ * @param {'before'|'after'} [options.returnDocument='before'] When set to `'after'`, returns the updated document rather than the original. The default is `'before'`.
1720
+ * @param {boolean} [options.returnOriginal=true] **Deprecated** Use `options.returnDocument` instead.
1692
1721
  * @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
1693
1722
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
1694
1723
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
1724
+ * @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
1695
1725
  * @param {ClientSession} [options.session] optional session to use for this operation
1696
1726
  * @param {Collection~findAndModifyCallback} [callback] The collection result callback
1697
1727
  * @return {Promise<Collection~findAndModifyWriteOpResultObject>} returns Promise if no callback passed
1698
1728
  */
1699
- Collection.prototype.findOneAndReplace = function(filter, replacement, options, callback) {
1700
- if (typeof options === 'function') (callback = options), (options = {});
1701
- options = options || {};
1729
+ Collection.prototype.findOneAndReplace = deprecateOptions(
1730
+ {
1731
+ name: 'collection.findOneAndReplace',
1732
+ deprecatedOptions: ['returnOriginal'],
1733
+ optionsIndex: 2
1734
+ },
1735
+ function(filter, replacement, options, callback) {
1736
+ if (typeof options === 'function') (callback = options), (options = {});
1737
+ options = options || {};
1702
1738
 
1703
- return executeOperation(
1704
- this.s.topology,
1705
- new FindOneAndReplaceOperation(this, filter, replacement, options),
1706
- callback
1707
- );
1708
- };
1739
+ // Add ignoreUndefined
1740
+ if (this.s.options.ignoreUndefined) {
1741
+ options = Object.assign({}, options);
1742
+ options.ignoreUndefined = this.s.options.ignoreUndefined;
1743
+ }
1744
+
1745
+ return executeOperation(
1746
+ this.s.topology,
1747
+ new FindOneAndReplaceOperation(this, filter, replacement, options),
1748
+ callback
1749
+ );
1750
+ }
1751
+ );
1709
1752
 
1710
1753
  /**
1711
1754
  * Find a document and update it in one atomic operation. Requires a write lock for the duration of the operation.
@@ -1722,24 +1765,39 @@ Collection.prototype.findOneAndReplace = function(filter, replacement, options,
1722
1765
  * @param {object} [options.projection] Limits the fields to return for all matching documents.
1723
1766
  * @param {object} [options.sort] Determines which document the operation modifies if the query selects multiple documents.
1724
1767
  * @param {boolean} [options.upsert=false] Upsert the document if it does not exist.
1725
- * @param {boolean} [options.returnOriginal=true] When false, returns the updated document rather than the original. The default is true.
1768
+ * @param {'before'|'after'} [options.returnDocument='before'] When set to `'after'`, returns the updated document rather than the original. The default is `'before'`.
1769
+ * @param {boolean} [options.returnOriginal=true] **Deprecated** Use `options.returnDocument` instead.
1726
1770
  * @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
1727
1771
  * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
1728
1772
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
1773
+ * @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
1729
1774
  * @param {ClientSession} [options.session] An ptional session to use for this operation
1730
1775
  * @param {Collection~findAndModifyCallback} [callback] The collection result callback
1731
1776
  * @return {Promise<Collection~findAndModifyWriteOpResultObject>} returns Promise if no callback passed
1732
1777
  */
1733
- Collection.prototype.findOneAndUpdate = function(filter, update, options, callback) {
1734
- if (typeof options === 'function') (callback = options), (options = {});
1735
- options = options || {};
1778
+ Collection.prototype.findOneAndUpdate = deprecateOptions(
1779
+ {
1780
+ name: 'collection.findOneAndUpdate',
1781
+ deprecatedOptions: ['returnOriginal'],
1782
+ optionsIndex: 2
1783
+ },
1784
+ function(filter, update, options, callback) {
1785
+ if (typeof options === 'function') (callback = options), (options = {});
1786
+ options = options || {};
1736
1787
 
1737
- return executeOperation(
1738
- this.s.topology,
1739
- new FindOneAndUpdateOperation(this, filter, update, options),
1740
- callback
1741
- );
1742
- };
1788
+ // Add ignoreUndefined
1789
+ if (this.s.options.ignoreUndefined) {
1790
+ options = Object.assign({}, options);
1791
+ options.ignoreUndefined = this.s.options.ignoreUndefined;
1792
+ }
1793
+
1794
+ return executeOperation(
1795
+ this.s.topology,
1796
+ new FindOneAndUpdateOperation(this, filter, update, options),
1797
+ callback
1798
+ );
1799
+ }
1800
+ );
1743
1801
 
1744
1802
  /**
1745
1803
  * Find and update a document.
@@ -1748,9 +1806,10 @@ Collection.prototype.findOneAndUpdate = function(filter, update, options, callba
1748
1806
  * @param {array} sort If multiple docs match, choose the first one in the specified sort order as the object to manipulate.
1749
1807
  * @param {object} doc The fields/vals to be updated.
1750
1808
  * @param {object} [options] Optional settings.
1751
- * @param {(number|string)} [options.w] The write concern.
1752
- * @param {number} [options.wtimeout] The write concern timeout.
1753
- * @param {boolean} [options.j=false] Specify a journal write concern.
1809
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
1810
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
1811
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
1812
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
1754
1813
  * @param {boolean} [options.remove=false] Set to true to remove the object before returning.
1755
1814
  * @param {boolean} [options.upsert=false] Perform an upsert operation.
1756
1815
  * @param {boolean} [options.new=false] Set to true if you want to return the modified object rather than the original. Ignored for remove.
@@ -1798,9 +1857,10 @@ function _findAndModify(query, sort, doc, options, callback) {
1798
1857
  * @param {object} query Query object to locate the object to modify.
1799
1858
  * @param {array} sort If multiple docs match, choose the first one in the specified sort order as the object to manipulate.
1800
1859
  * @param {object} [options] Optional settings.
1801
- * @param {(number|string)} [options.w] The write concern.
1802
- * @param {number} [options.wtimeout] The write concern timeout.
1803
- * @param {boolean} [options.j=false] Specify a journal write concern.
1860
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
1861
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
1862
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
1863
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
1804
1864
  * @param {ClientSession} [options.session] optional session to use for this operation
1805
1865
  * @param {Collection~resultCallback} [callback] The command result callback
1806
1866
  * @return {Promise} returns Promise if no callback passed
@@ -1831,7 +1891,6 @@ Collection.prototype.findAndRemove = deprecate(function(query, sort, options, ca
1831
1891
  * @param {number} [options.batchSize=1000] The number of documents to return per batch. See {@link https://docs.mongodb.com/manual/reference/command/aggregate|aggregation documentation}.
1832
1892
  * @param {object} [options.cursor] Return the query as cursor, on 2.6 > it returns as a real cursor on pre 2.6 it returns as an emulated cursor.
1833
1893
  * @param {number} [options.cursor.batchSize=1000] Deprecated. Use `options.batchSize`
1834
- * @param {boolean} [options.explain=false] Explain returns the aggregation execution plan (requires mongodb 2.6 >).
1835
1894
  * @param {boolean} [options.allowDiskUse=false] allowDiskUse lets the server know if it can use disk to store temporary results for the aggregation (requires mongodb 2.6 >).
1836
1895
  * @param {number} [options.maxTimeMS] maxTimeMS specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point.
1837
1896
  * @param {number} [options.maxAwaitTimeMS] The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query.
@@ -1843,6 +1902,7 @@ Collection.prototype.findAndRemove = deprecate(function(query, sort, options, ca
1843
1902
  * @param {object} [options.collation] Specify collation settings for operation. See {@link https://docs.mongodb.com/manual/reference/command/aggregate|aggregation documentation}.
1844
1903
  * @param {string} [options.comment] Add a comment to an aggregation command
1845
1904
  * @param {string|object} [options.hint] Add an index selection hint to an aggregation command
1905
+ * @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
1846
1906
  * @param {ClientSession} [options.session] optional session to use for this operation
1847
1907
  * @param {Collection~aggregationCallback} callback The command result callback
1848
1908
  * @return {(null|AggregationCursor)}
@@ -2089,6 +2149,7 @@ Collection.prototype.group = deprecate(function(
2089
2149
  * @param {boolean} [options.jsMode=false] It is possible to make the execution stay in JS. Provided in MongoDB > 2.0.X.
2090
2150
  * @param {boolean} [options.verbose=false] Provide statistics on job execution time.
2091
2151
  * @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
2152
+ * @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
2092
2153
  * @param {ClientSession} [options.session] optional session to use for this operation
2093
2154
  * @param {Collection~resultCallback} [callback] The command result callback
2094
2155
  * @throws {MongoError}
@@ -2124,9 +2185,10 @@ Collection.prototype.mapReduce = function(map, reduce, options, callback) {
2124
2185
  *
2125
2186
  * @method
2126
2187
  * @param {object} [options] Optional settings.
2127
- * @param {(number|string)} [options.w] The write concern.
2128
- * @param {number} [options.wtimeout] The write concern timeout.
2129
- * @param {boolean} [options.j=false] Specify a journal write concern.
2188
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
2189
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
2190
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
2191
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
2130
2192
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
2131
2193
  * @param {ClientSession} [options.session] optional session to use for this operation
2132
2194
  * @return {UnorderedBulkOperation}
@@ -2147,12 +2209,12 @@ Collection.prototype.initializeUnorderedBulkOp = function(options) {
2147
2209
  *
2148
2210
  * @method
2149
2211
  * @param {object} [options] Optional settings.
2150
- * @param {(number|string)} [options.w] The write concern.
2151
- * @param {number} [options.wtimeout] The write concern timeout.
2152
- * @param {boolean} [options.j=false] Specify a journal write concern.
2212
+ * @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
2213
+ * @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
2214
+ * @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
2215
+ * @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
2153
2216
  * @param {ClientSession} [options.session] optional session to use for this operation
2154
2217
  * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
2155
- * @param {OrderedBulkOperation} callback The command result callback
2156
2218
  * @return {null}
2157
2219
  */
2158
2220
  Collection.prototype.initializeOrderedBulkOp = function(options) {
@@ -49,16 +49,16 @@ class MongoCredentials {
49
49
  this.mechanism = options.mechanism || 'default';
50
50
  this.mechanismProperties = options.mechanismProperties || {};
51
51
 
52
- if (this.mechanism.match(/MONGODB-AWS/i)) {
53
- if (this.username == null && process.env.AWS_ACCESS_KEY_ID) {
52
+ if (/MONGODB-AWS/i.test(this.mechanism)) {
53
+ if (!this.username && process.env.AWS_ACCESS_KEY_ID) {
54
54
  this.username = process.env.AWS_ACCESS_KEY_ID;
55
55
  }
56
56
 
57
- if (this.password == null && process.env.AWS_SECRET_ACCESS_KEY) {
57
+ if (!this.password && process.env.AWS_SECRET_ACCESS_KEY) {
58
58
  this.password = process.env.AWS_SECRET_ACCESS_KEY;
59
59
  }
60
60
 
61
- if (this.mechanismProperties.AWS_SESSION_TOKEN == null && process.env.AWS_SESSION_TOKEN) {
61
+ if (!this.mechanismProperties.AWS_SESSION_TOKEN && process.env.AWS_SESSION_TOKEN) {
62
62
  this.mechanismProperties.AWS_SESSION_TOKEN = process.env.AWS_SESSION_TOKEN;
63
63
  }
64
64
  }
@@ -90,7 +90,7 @@ class MongoCredentials {
90
90
  */
91
91
  resolveAuthMechanism(ismaster) {
92
92
  // If the mechanism is not "default", then it does not need to be resolved
93
- if (this.mechanism.match(/DEFAULT/i)) {
93
+ if (/DEFAULT/i.test(this.mechanism)) {
94
94
  return new MongoCredentials({
95
95
  username: this.username,
96
96
  password: this.password,
@@ -4,6 +4,7 @@ const Buffer = require('safe-buffer').Buffer;
4
4
  const retrieveBSON = require('../connection/utils').retrieveBSON;
5
5
  const MongoError = require('../error').MongoError;
6
6
  const AuthProvider = require('./auth_provider').AuthProvider;
7
+ const emitWarningOnce = require('../../utils').emitWarning;
7
8
 
8
9
  const BSON = retrieveBSON();
9
10
  const Binary = BSON.Binary;
@@ -24,7 +25,7 @@ class ScramSHA extends AuthProvider {
24
25
  prepare(handshakeDoc, authContext, callback) {
25
26
  const cryptoMethod = this.cryptoMethod;
26
27
  if (cryptoMethod === 'sha256' && saslprep == null) {
27
- console.warn('Warning: no saslprep library specified. Passwords will not be sanitized');
28
+ emitWarningOnce('Warning: no saslprep library specified. Passwords will not be sanitized');
28
29
  }
29
30
 
30
31
  crypto.randomBytes(24, (err, nonce) => {
@@ -243,7 +243,7 @@ function parseSslOptions(family, options) {
243
243
  }
244
244
 
245
245
  // Set default sni servername to be the same as host
246
- if (result.servername == null) {
246
+ if (result.servername == null && !net.isIP(result.host)) {
247
247
  result.servername = result.host;
248
248
  }
249
249
 
@@ -37,6 +37,7 @@ var Logger = function(className, options) {
37
37
  if (options.logger) {
38
38
  currentLogger = options.logger;
39
39
  } else if (currentLogger == null) {
40
+ // eslint-disable-next-line no-console
40
41
  currentLogger = console.log;
41
42
  }
42
43
 
@@ -31,6 +31,7 @@ const Buffer = require('safe-buffer').Buffer;
31
31
  const opcodes = require('../wireprotocol/shared').opcodes;
32
32
  const databaseNamespace = require('../wireprotocol/shared').databaseNamespace;
33
33
  const ReadPreference = require('../topologies/read_preference');
34
+ const MongoError = require('../../core/error').MongoError;
34
35
 
35
36
  // Incrementing request id
36
37
  let _requestId = 0;
@@ -196,7 +197,8 @@ class BinMsg {
196
197
  while (this.index < this.data.length) {
197
198
  const payloadType = this.data.readUInt8(this.index++);
198
199
  if (payloadType === 1) {
199
- console.error('TYPE 1');
200
+ // It was decided that no driver makes use of payload type 1
201
+ throw new MongoError('OP_MSG Payload Type 1 detected unsupported protocol');
200
202
  } else if (payloadType === 0) {
201
203
  const bsonSize = this.data.readUInt32LE(this.index);
202
204
  const bin = this.data.slice(this.index, this.index + bsonSize);