mongodb 3.2.5 → 3.3.0-beta2

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 (133) hide show
  1. package/HISTORY.md +0 -10
  2. package/index.js +4 -4
  3. package/lib/admin.js +56 -56
  4. package/lib/aggregation_cursor.js +7 -3
  5. package/lib/bulk/common.js +18 -13
  6. package/lib/change_stream.js +196 -89
  7. package/lib/collection.js +217 -169
  8. package/lib/command_cursor.js +17 -7
  9. package/lib/core/auth/auth_provider.js +158 -0
  10. package/lib/core/auth/defaultAuthProviders.js +29 -0
  11. package/lib/core/auth/gssapi.js +241 -0
  12. package/lib/core/auth/mongo_credentials.js +81 -0
  13. package/lib/core/auth/mongocr.js +51 -0
  14. package/lib/core/auth/plain.js +35 -0
  15. package/lib/core/auth/scram.js +293 -0
  16. package/lib/core/auth/sspi.js +131 -0
  17. package/lib/core/auth/x509.js +26 -0
  18. package/lib/core/connection/apm.js +236 -0
  19. package/lib/core/connection/command_result.js +36 -0
  20. package/lib/core/connection/commands.js +507 -0
  21. package/lib/core/connection/connect.js +370 -0
  22. package/lib/core/connection/connection.js +624 -0
  23. package/lib/core/connection/logger.js +246 -0
  24. package/lib/core/connection/msg.js +219 -0
  25. package/lib/core/connection/pool.js +1285 -0
  26. package/lib/core/connection/utils.js +57 -0
  27. package/lib/core/cursor.js +752 -0
  28. package/lib/core/error.js +186 -0
  29. package/lib/core/index.js +50 -0
  30. package/lib/core/sdam/monitoring.js +228 -0
  31. package/lib/core/sdam/server.js +467 -0
  32. package/lib/core/sdam/server_description.js +163 -0
  33. package/lib/core/sdam/server_selectors.js +244 -0
  34. package/lib/core/sdam/srv_polling.js +135 -0
  35. package/lib/core/sdam/topology.js +1151 -0
  36. package/lib/core/sdam/topology_description.js +408 -0
  37. package/lib/core/sessions.js +711 -0
  38. package/lib/core/tools/smoke_plugin.js +61 -0
  39. package/lib/core/topologies/mongos.js +1337 -0
  40. package/lib/core/topologies/read_preference.js +202 -0
  41. package/lib/core/topologies/replset.js +1507 -0
  42. package/lib/core/topologies/replset_state.js +1121 -0
  43. package/lib/core/topologies/server.js +984 -0
  44. package/lib/core/topologies/shared.js +453 -0
  45. package/lib/core/transactions.js +167 -0
  46. package/lib/core/uri_parser.js +631 -0
  47. package/lib/core/utils.js +165 -0
  48. package/lib/core/wireprotocol/command.js +170 -0
  49. package/lib/core/wireprotocol/compression.js +73 -0
  50. package/lib/core/wireprotocol/constants.js +13 -0
  51. package/lib/core/wireprotocol/get_more.js +86 -0
  52. package/lib/core/wireprotocol/index.js +18 -0
  53. package/lib/core/wireprotocol/kill_cursors.js +70 -0
  54. package/lib/core/wireprotocol/query.js +224 -0
  55. package/lib/core/wireprotocol/shared.js +115 -0
  56. package/lib/core/wireprotocol/write_command.js +50 -0
  57. package/lib/cursor.js +40 -46
  58. package/lib/db.js +141 -95
  59. package/lib/dynamic_loaders.js +32 -0
  60. package/lib/error.js +12 -10
  61. package/lib/gridfs/chunk.js +2 -2
  62. package/lib/gridfs/grid_store.js +31 -25
  63. package/lib/gridfs-stream/index.js +4 -4
  64. package/lib/gridfs-stream/upload.js +1 -1
  65. package/lib/mongo_client.js +37 -15
  66. package/lib/operations/add_user.js +96 -0
  67. package/lib/operations/aggregate.js +24 -13
  68. package/lib/operations/aggregate_operation.js +127 -0
  69. package/lib/operations/bulk_write.js +104 -0
  70. package/lib/operations/close.js +47 -0
  71. package/lib/operations/collection_ops.js +28 -287
  72. package/lib/operations/collections.js +55 -0
  73. package/lib/operations/command.js +120 -0
  74. package/lib/operations/command_v2.js +43 -0
  75. package/lib/operations/common_functions.js +372 -0
  76. package/lib/operations/{mongo_client_ops.js → connect.js} +185 -157
  77. package/lib/operations/count.js +72 -0
  78. package/lib/operations/count_documents.js +46 -0
  79. package/lib/operations/create_collection.js +118 -0
  80. package/lib/operations/create_index.js +92 -0
  81. package/lib/operations/create_indexes.js +61 -0
  82. package/lib/operations/cursor_ops.js +3 -4
  83. package/lib/operations/db_ops.js +15 -12
  84. package/lib/operations/delete_many.js +25 -0
  85. package/lib/operations/delete_one.js +25 -0
  86. package/lib/operations/distinct.js +85 -0
  87. package/lib/operations/drop.js +53 -0
  88. package/lib/operations/drop_index.js +42 -0
  89. package/lib/operations/drop_indexes.js +23 -0
  90. package/lib/operations/estimated_document_count.js +33 -0
  91. package/lib/operations/execute_db_admin_command.js +34 -0
  92. package/lib/operations/execute_operation.js +165 -0
  93. package/lib/operations/explain.js +23 -0
  94. package/lib/operations/find_and_modify.js +98 -0
  95. package/lib/operations/find_one.js +33 -0
  96. package/lib/operations/find_one_and_delete.js +16 -0
  97. package/lib/operations/find_one_and_replace.js +18 -0
  98. package/lib/operations/find_one_and_update.js +19 -0
  99. package/lib/operations/geo_haystack_search.js +79 -0
  100. package/lib/operations/has_next.js +40 -0
  101. package/lib/operations/index_exists.js +39 -0
  102. package/lib/operations/index_information.js +23 -0
  103. package/lib/operations/indexes.js +22 -0
  104. package/lib/operations/insert_many.js +63 -0
  105. package/lib/operations/insert_one.js +75 -0
  106. package/lib/operations/is_capped.js +19 -0
  107. package/lib/operations/list_indexes.js +66 -0
  108. package/lib/operations/map_reduce.js +189 -0
  109. package/lib/operations/next.js +32 -0
  110. package/lib/operations/operation.js +63 -0
  111. package/lib/operations/options_operation.js +32 -0
  112. package/lib/operations/profiling_level.js +31 -0
  113. package/lib/operations/re_index.js +28 -0
  114. package/lib/operations/remove_user.js +52 -0
  115. package/lib/operations/rename.js +61 -0
  116. package/lib/operations/replace_one.js +47 -0
  117. package/lib/operations/set_profiling_level.js +48 -0
  118. package/lib/operations/stats.js +45 -0
  119. package/lib/operations/to_array.js +68 -0
  120. package/lib/operations/update_many.js +29 -0
  121. package/lib/operations/update_one.js +44 -0
  122. package/lib/operations/validate_collection.js +40 -0
  123. package/lib/read_concern.js +55 -0
  124. package/lib/topologies/mongos.js +3 -3
  125. package/lib/topologies/native_topology.js +22 -2
  126. package/lib/topologies/replset.js +3 -3
  127. package/lib/topologies/server.js +4 -4
  128. package/lib/topologies/topology_base.js +6 -6
  129. package/lib/url_parser.js +4 -3
  130. package/lib/utils.js +46 -59
  131. package/lib/write_concern.js +66 -0
  132. package/package.json +15 -6
  133. package/lib/.DS_Store +0 -0
package/HISTORY.md CHANGED
@@ -2,16 +2,6 @@
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.5"></a>
6
- ## [3.2.5](https://github.com/mongodb/node-mongodb-native/compare/v3.2.4...v3.2.5) (2019-05-17)
7
-
8
-
9
- ### Bug Fixes
10
-
11
- * **core:** updating core to 3.2.5 ([a2766c1](https://github.com/mongodb/node-mongodb-native/commit/a2766c1))
12
-
13
-
14
-
15
5
  <a name="3.2.4"></a>
16
6
  ## [3.2.4](https://github.com/mongodb/node-mongodb-native/compare/v3.2.2...v3.2.4) (2019-05-08)
17
7
 
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  // Core module
4
- const core = require('mongodb-core');
4
+ const core = require('./lib/core');
5
5
  const Instrumentation = require('./lib/apm');
6
6
 
7
7
  // Set up the connect function
@@ -19,7 +19,7 @@ connect.Collection = require('./lib/collection');
19
19
  connect.Server = require('./lib/topologies/server');
20
20
  connect.ReplSet = require('./lib/topologies/replset');
21
21
  connect.Mongos = require('./lib/topologies/mongos');
22
- connect.ReadPreference = require('mongodb-core').ReadPreference;
22
+ connect.ReadPreference = core.ReadPreference;
23
23
  connect.GridStore = require('./lib/gridfs/grid_store');
24
24
  connect.Chunk = require('./lib/gridfs/chunk');
25
25
  connect.Logger = core.Logger;
@@ -28,8 +28,8 @@ connect.CommandCursor = require('./lib/command_cursor');
28
28
  connect.Cursor = require('./lib/cursor');
29
29
  connect.GridFSBucket = require('./lib/gridfs-stream');
30
30
  // Exported to be used in tests not to be used anywhere else
31
- connect.CoreServer = require('mongodb-core').Server;
32
- connect.CoreConnection = require('mongodb-core').Connection;
31
+ connect.CoreServer = core.Server;
32
+ connect.CoreConnection = core.Connection;
33
33
 
34
34
  // BSON types exported
35
35
  connect.Binary = core.BSON.Binary;
package/lib/admin.js CHANGED
@@ -1,14 +1,13 @@
1
1
  'use strict';
2
2
 
3
- const executeOperation = require('./utils').executeOperation;
4
3
  const applyWriteConcern = require('./utils').applyWriteConcern;
5
4
 
6
- const addUser = require('./operations/db_ops').addUser;
7
- const executeDbAdminCommand = require('./operations/db_ops').executeDbAdminCommand;
8
- const removeUser = require('./operations/db_ops').removeUser;
9
- const replSetGetStatus = require('./operations/admin_ops').replSetGetStatus;
10
- const serverStatus = require('./operations/admin_ops').serverStatus;
11
- const validateCollection = require('./operations/admin_ops').validateCollection;
5
+ const AddUserOperation = require('./operations/add_user');
6
+ const ExecuteDbAdminCommandOperation = require('./operations/execute_db_admin_command');
7
+ const RemoveUserOperation = require('./operations/remove_user');
8
+ const ValidateCollectionOperation = require('./operations/validate_collection');
9
+
10
+ const executeOperation = require('./operations/execute_operation');
12
11
 
13
12
  /**
14
13
  * @fileOverview The **Admin** class is an internal class that allows convenient access to
@@ -75,12 +74,9 @@ Admin.prototype.command = function(command, options, callback) {
75
74
  callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
76
75
  options = args.length ? args.shift() : {};
77
76
 
78
- return executeOperation(this.s.db.s.topology, executeDbAdminCommand.bind(this.s.db), [
79
- this.s.db,
80
- command,
81
- options,
82
- callback
83
- ]);
77
+ const commandOperation = new ExecuteDbAdminCommandOperation(this.s.db, command, options);
78
+
79
+ return executeOperation(this.s.db.s.topology, commandOperation, callback);
84
80
  };
85
81
 
86
82
  /**
@@ -97,12 +93,10 @@ Admin.prototype.buildInfo = function(options, callback) {
97
93
  options = options || {};
98
94
 
99
95
  const cmd = { buildinfo: 1 };
100
- return executeOperation(this.s.db.s.topology, executeDbAdminCommand.bind(this.s.db), [
101
- this.s.db,
102
- cmd,
103
- options,
104
- callback
105
- ]);
96
+
97
+ const buildInfoOperation = new ExecuteDbAdminCommandOperation(this.s.db, cmd, options);
98
+
99
+ return executeOperation(this.s.db.s.topology, buildInfoOperation, callback);
106
100
  };
107
101
 
108
102
  /**
@@ -119,12 +113,10 @@ Admin.prototype.serverInfo = function(options, callback) {
119
113
  options = options || {};
120
114
 
121
115
  const cmd = { buildinfo: 1 };
122
- return executeOperation(this.s.db.s.topology, executeDbAdminCommand.bind(this.s.db), [
123
- this.s.db,
124
- cmd,
125
- options,
126
- callback
127
- ]);
116
+
117
+ const serverInfoOperation = new ExecuteDbAdminCommandOperation(this.s.db, cmd, options);
118
+
119
+ return executeOperation(this.s.db.s.topology, serverInfoOperation, callback);
128
120
  };
129
121
 
130
122
  /**
@@ -139,7 +131,13 @@ Admin.prototype.serverStatus = function(options, callback) {
139
131
  if (typeof options === 'function') (callback = options), (options = {});
140
132
  options = options || {};
141
133
 
142
- return executeOperation(this.s.db.s.topology, serverStatus, [this, options, callback]);
134
+ const serverStatusOperation = new ExecuteDbAdminCommandOperation(
135
+ this.s.db,
136
+ { serverStatus: 1 },
137
+ options
138
+ );
139
+
140
+ return executeOperation(this.s.db.s.topology, serverStatusOperation, callback);
143
141
  };
144
142
 
145
143
  /**
@@ -155,12 +153,10 @@ Admin.prototype.ping = function(options, callback) {
155
153
  options = options || {};
156
154
 
157
155
  const cmd = { ping: 1 };
158
- return executeOperation(this.s.db.s.topology, executeDbAdminCommand.bind(this.s.db), [
159
- this.s.db,
160
- cmd,
161
- options,
162
- callback
163
- ]);
156
+
157
+ const pingOperation = new ExecuteDbAdminCommandOperation(this.s.db, cmd, options);
158
+
159
+ return executeOperation(this.s.db.s.topology, pingOperation, callback);
164
160
  };
165
161
 
166
162
  /**
@@ -183,6 +179,12 @@ Admin.prototype.addUser = function(username, password, options, callback) {
183
179
  const args = Array.prototype.slice.call(arguments, 2);
184
180
  callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
185
181
 
182
+ // Special case where there is no password ($external users)
183
+ if (typeof username === 'string' && password != null && typeof password === 'object') {
184
+ options = password;
185
+ password = null;
186
+ }
187
+
186
188
  options = args.length ? args.shift() : {};
187
189
  options = Object.assign({}, options);
188
190
  // Get the options
@@ -190,13 +192,9 @@ Admin.prototype.addUser = function(username, password, options, callback) {
190
192
  // Set the db name to admin
191
193
  options.dbName = 'admin';
192
194
 
193
- return executeOperation(this.s.db.s.topology, addUser, [
194
- this.s.db,
195
- username,
196
- password,
197
- options,
198
- callback
199
- ]);
195
+ const addUserOperation = new AddUserOperation(this.s.db, username, password, options);
196
+
197
+ return executeOperation(this.s.db.s.topology, addUserOperation, callback);
200
198
  };
201
199
 
202
200
  /**
@@ -223,12 +221,9 @@ Admin.prototype.removeUser = function(username, options, callback) {
223
221
  // Set the db name
224
222
  options.dbName = 'admin';
225
223
 
226
- return executeOperation(this.s.db.s.topology, removeUser, [
227
- this.s.db,
228
- username,
229
- options,
230
- callback
231
- ]);
224
+ const removeUserOperation = new RemoveUserOperation(this.s.db, username, options);
225
+
226
+ return executeOperation(this.s.db.s.topology, removeUserOperation, callback);
232
227
  };
233
228
 
234
229
  /**
@@ -244,12 +239,13 @@ Admin.prototype.validateCollection = function(collectionName, options, callback)
244
239
  if (typeof options === 'function') (callback = options), (options = {});
245
240
  options = options || {};
246
241
 
247
- return executeOperation(this.s.db.s.topology, validateCollection, [
242
+ const validateCollectionOperation = new ValidateCollectionOperation(
248
243
  this,
249
244
  collectionName,
250
- options,
251
- callback
252
- ]);
245
+ options
246
+ );
247
+
248
+ return executeOperation(this.s.db.s.topology, validateCollectionOperation, callback);
253
249
  };
254
250
 
255
251
  /**
@@ -267,12 +263,10 @@ Admin.prototype.listDatabases = function(options, callback) {
267
263
 
268
264
  const cmd = { listDatabases: 1 };
269
265
  if (options.nameOnly) cmd.nameOnly = Number(cmd.nameOnly);
270
- return executeOperation(this.s.db.s.topology, executeDbAdminCommand.bind(this.s.db), [
271
- this.s.db,
272
- cmd,
273
- options,
274
- callback
275
- ]);
266
+
267
+ const listDatabasesOperation = new ExecuteDbAdminCommandOperation(this.s.db, cmd, options);
268
+
269
+ return executeOperation(this.s.db.s.topology, listDatabasesOperation, callback);
276
270
  };
277
271
 
278
272
  /**
@@ -287,7 +281,13 @@ Admin.prototype.replSetGetStatus = function(options, callback) {
287
281
  if (typeof options === 'function') (callback = options), (options = {});
288
282
  options = options || {};
289
283
 
290
- return executeOperation(this.s.db.s.topology, replSetGetStatus, [this, options, callback]);
284
+ const replSetGetStatusOperation = new ExecuteDbAdminCommandOperation(
285
+ this.s.db,
286
+ { replSetGetStatus: 1 },
287
+ options
288
+ );
289
+
290
+ return executeOperation(this.s.db.s.topology, replSetGetStatusOperation, callback);
291
291
  };
292
292
 
293
293
  module.exports = Admin;
@@ -1,11 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  const inherits = require('util').inherits;
4
- const MongoError = require('mongodb-core').MongoError;
4
+ const MongoError = require('./core').MongoError;
5
5
  const Readable = require('stream').Readable;
6
6
  const CoreCursor = require('./cursor');
7
7
  const deprecate = require('util').deprecate;
8
8
  const SUPPORTS = require('./utils').SUPPORTS;
9
+ const MongoDBNamespace = require('./utils').MongoDBNamespace;
9
10
 
10
11
  /**
11
12
  * @fileOverview The **AggregationCursor** class is an internal class that embodies an aggregation cursor on MongoDB
@@ -55,10 +56,12 @@ const SUPPORTS = require('./utils').SUPPORTS;
55
56
  * @fires AggregationCursor#readable
56
57
  * @return {AggregationCursor} an AggregationCursor instance.
57
58
  */
58
- var AggregationCursor = function(bson, ns, cmd, options, topology, topologyOptions) {
59
+ var AggregationCursor = function(topology, ns, cmd, options) {
59
60
  CoreCursor.apply(this, Array.prototype.slice.call(arguments, 0));
60
61
  var state = AggregationCursor.INIT;
61
62
  var streamOptions = {};
63
+ const bson = topology.s.bson;
64
+ const topologyOptions = topology.s.options;
62
65
 
63
66
  // MaxTimeMS
64
67
  var maxTimeMS = null;
@@ -80,7 +83,8 @@ var AggregationCursor = function(bson, ns, cmd, options, topology, topologyOptio
80
83
  // BSON
81
84
  bson: bson,
82
85
  // Namespace
83
- ns: ns,
86
+ // TODO: switch to raw namespace object later
87
+ namespace: MongoDBNamespace.fromString(ns),
84
88
  // Command
85
89
  cmd: cmd,
86
90
  // Options
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
- const Long = require('mongodb-core').BSON.Long;
4
- const MongoError = require('mongodb-core').MongoError;
5
- const ObjectID = require('mongodb-core').BSON.ObjectID;
6
- const BSON = require('mongodb-core').BSON;
7
- const MongoWriteConcernError = require('mongodb-core').MongoWriteConcernError;
3
+ const Long = require('../core').BSON.Long;
4
+ const MongoError = require('../core').MongoError;
5
+ const ObjectID = require('../core').BSON.ObjectID;
6
+ const BSON = require('../core').BSON;
7
+ const MongoWriteConcernError = require('../core').MongoWriteConcernError;
8
8
  const toError = require('../utils').toError;
9
9
  const handleCallback = require('../utils').handleCallback;
10
10
  const applyRetryableWrites = require('../utils').applyRetryableWrites;
11
11
  const applyWriteConcern = require('../utils').applyWriteConcern;
12
- const executeOperation = require('../utils').executeOperation;
12
+ const executeLegacyOperation = require('../utils').executeLegacyOperation;
13
13
  const isPromiseLike = require('../utils').isPromiseLike;
14
14
 
15
15
  // Error codes
@@ -708,7 +708,7 @@ class BulkOperationBase {
708
708
  options = options == null ? {} : options;
709
709
  // TODO Bring from driver information in isMaster
710
710
  // Get the namespace for the write operations
711
- const namespace = collection.collectionName;
711
+ const namespace = collection.s.namespace;
712
712
  // Used to mark operation as executed
713
713
  const executed = false;
714
714
 
@@ -1007,7 +1007,7 @@ class BulkOperationBase {
1007
1007
  options = ret.options;
1008
1008
  callback = ret.callback;
1009
1009
 
1010
- return executeOperation(this.s.topology, executeCommands, [this, options, callback]);
1010
+ return executeLegacyOperation(this.s.topology, executeCommands, [this, options, callback]);
1011
1011
  }
1012
1012
 
1013
1013
  /**
@@ -1069,21 +1069,21 @@ class BulkOperationBase {
1069
1069
  try {
1070
1070
  if (config.batch.batchType === INSERT) {
1071
1071
  this.s.topology.insert(
1072
- this.s.collection.namespace,
1072
+ this.s.namespace,
1073
1073
  config.batch.operations,
1074
1074
  finalOptions,
1075
1075
  config.resultHandler
1076
1076
  );
1077
1077
  } else if (config.batch.batchType === UPDATE) {
1078
1078
  this.s.topology.update(
1079
- this.s.collection.namespace,
1079
+ this.s.namespace,
1080
1080
  config.batch.operations,
1081
1081
  finalOptions,
1082
1082
  config.resultHandler
1083
1083
  );
1084
1084
  } else if (config.batch.batchType === REMOVE) {
1085
1085
  this.s.topology.remove(
1086
- this.s.collection.namespace,
1086
+ this.s.namespace,
1087
1087
  config.batch.operations,
1088
1088
  finalOptions,
1089
1089
  config.resultHandler
@@ -1115,11 +1115,15 @@ class BulkOperationBase {
1115
1115
  return true;
1116
1116
  }
1117
1117
 
1118
+ const msg = this.s.bulkResult.writeErrors[0].errmsg
1119
+ ? this.s.bulkResult.writeErrors[0].errmsg
1120
+ : 'write operation failed';
1121
+
1118
1122
  handleCallback(
1119
1123
  callback,
1120
1124
  new BulkWriteError(
1121
1125
  toError({
1122
- message: 'write operation failed',
1126
+ message: msg,
1123
1127
  code: this.s.bulkResult.writeErrors[0].code,
1124
1128
  writeErrors: this.s.bulkResult.writeErrors
1125
1129
  }),
@@ -1153,5 +1157,6 @@ module.exports = {
1153
1157
  bson,
1154
1158
  INSERT: INSERT,
1155
1159
  UPDATE: UPDATE,
1156
- REMOVE: REMOVE
1160
+ REMOVE: REMOVE,
1161
+ BulkWriteError
1157
1162
  };