mongodb 3.0.4 → 3.0.8
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/.eslintrc +2 -1
- package/CHANGES_3.0.0.md +28 -0
- package/CODE_OF_CONDUCT.md +80 -0
- package/CONTRIBUTING.md +29 -0
- package/HISTORY.md +52 -0
- package/conf.json +0 -1
- package/index.js +6 -4
- package/lib/admin.js +6 -49
- package/lib/aggregation_cursor.js +7 -46
- package/lib/apm.js +21 -629
- package/lib/bulk/common.js +0 -23
- package/lib/bulk/ordered.js +15 -22
- package/lib/bulk/unordered.js +15 -22
- package/lib/collection.js +60 -182
- package/lib/command_cursor.js +11 -34
- package/lib/cursor.js +48 -90
- package/lib/db.js +55 -124
- package/lib/gridfs/grid_store.js +12 -61
- package/lib/mongo_client.js +37 -31
- package/lib/topologies/mongos.js +47 -41
- package/lib/topologies/replset.js +46 -39
- package/lib/topologies/server.js +46 -40
- package/lib/topologies/topology_base.js +2 -4
- package/lib/url_parser.js +10 -0
- package/lib/utils.js +52 -5
- package/package.json +5 -5
- package/lib/metadata.js +0 -70
- package/yarn.lock +0 -3904
package/lib/mongo_client.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
executeOperation = require('./utils').executeOperation;
|
|
3
|
+
const parse = require('./url_parser');
|
|
4
|
+
const Server = require('./topologies/server');
|
|
5
|
+
const Mongos = require('./topologies/mongos');
|
|
6
|
+
const ReplSet = require('./topologies/replset');
|
|
7
|
+
const EventEmitter = require('events').EventEmitter;
|
|
8
|
+
const inherits = require('util').inherits;
|
|
9
|
+
const ReadPreference = require('mongodb-core').ReadPreference;
|
|
10
|
+
const Logger = require('mongodb-core').Logger;
|
|
11
|
+
const MongoError = require('mongodb-core').MongoError;
|
|
12
|
+
const handleCallback = require('./utils').handleCallback;
|
|
13
|
+
const Db = require('./db');
|
|
14
|
+
const f = require('util').format;
|
|
15
|
+
const shallowClone = require('./utils').shallowClone;
|
|
16
|
+
const authenticate = require('./authenticate');
|
|
17
|
+
const ServerSessionPool = require('mongodb-core').Sessions.ServerSessionPool;
|
|
18
|
+
const executeOperation = require('./utils').executeOperation;
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* @fileOverview The **MongoClient** class is a class that allows for making Connections to MongoDB.
|
|
@@ -106,7 +105,8 @@ var validOptionNames = [
|
|
|
106
105
|
'readPreferenceTags',
|
|
107
106
|
'numberOfRetries',
|
|
108
107
|
'auto_reconnect',
|
|
109
|
-
'minSize'
|
|
108
|
+
'minSize',
|
|
109
|
+
'monitorCommands'
|
|
110
110
|
];
|
|
111
111
|
|
|
112
112
|
var ignoreOptionNames = ['native_parser'];
|
|
@@ -199,11 +199,13 @@ function validOptions(options) {
|
|
|
199
199
|
* @param {array} [options.readPreferenceTags=null] Read preference tags
|
|
200
200
|
* @param {number} [options.numberOfRetries=5] The number of retries for a tailable cursor
|
|
201
201
|
* @param {boolean} [options.auto_reconnect=true] Enable auto reconnecting for single server instances
|
|
202
|
+
* @param {boolean} [options.monitorCommands=false] Enable command monitoring for this client
|
|
203
|
+
* @param {number} [options.minSize] If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections
|
|
202
204
|
* @param {MongoClient~connectCallback} [callback] The command result callback
|
|
203
205
|
* @return {MongoClient} a MongoClient instance
|
|
204
206
|
*/
|
|
205
207
|
function MongoClient(url, options) {
|
|
206
|
-
if (!(this instanceof MongoClient)) return new MongoClient();
|
|
208
|
+
if (!(this instanceof MongoClient)) return new MongoClient(url, options);
|
|
207
209
|
|
|
208
210
|
// Set up event emitter
|
|
209
211
|
EventEmitter.call(this);
|
|
@@ -229,8 +231,6 @@ function MongoClient(url, options) {
|
|
|
229
231
|
*/
|
|
230
232
|
inherits(MongoClient, EventEmitter);
|
|
231
233
|
|
|
232
|
-
var define = (MongoClient.define = new Define('MongoClient', MongoClient, false));
|
|
233
|
-
|
|
234
234
|
/**
|
|
235
235
|
* The callback format for results
|
|
236
236
|
* @callback MongoClient~connectCallback
|
|
@@ -272,8 +272,6 @@ const connectOp = (self, err, callback) => {
|
|
|
272
272
|
});
|
|
273
273
|
};
|
|
274
274
|
|
|
275
|
-
define.classMethod('close', { callback: true, promise: true, returns: [MongoClient] });
|
|
276
|
-
|
|
277
275
|
/**
|
|
278
276
|
* Logout user from server, fire off on all connections and remove all auth info
|
|
279
277
|
* @method
|
|
@@ -301,8 +299,6 @@ const logout = (self, dbName, callback) => {
|
|
|
301
299
|
});
|
|
302
300
|
};
|
|
303
301
|
|
|
304
|
-
define.classMethod('logout', { callback: true, promise: true });
|
|
305
|
-
|
|
306
302
|
/**
|
|
307
303
|
* Close the db and its underlying connections
|
|
308
304
|
* @method
|
|
@@ -313,7 +309,8 @@ define.classMethod('logout', { callback: true, promise: true });
|
|
|
313
309
|
MongoClient.prototype.close = function(force, callback) {
|
|
314
310
|
var self = this;
|
|
315
311
|
if (typeof force === 'function') (callback = force), (force = false);
|
|
316
|
-
|
|
312
|
+
|
|
313
|
+
// Close the topology connection
|
|
317
314
|
this.topology.close(force);
|
|
318
315
|
|
|
319
316
|
// Emit close event
|
|
@@ -339,8 +336,6 @@ MongoClient.prototype.close = function(force, callback) {
|
|
|
339
336
|
});
|
|
340
337
|
};
|
|
341
338
|
|
|
342
|
-
define.classMethod('close', { callback: true, promise: true });
|
|
343
|
-
|
|
344
339
|
/**
|
|
345
340
|
* Create a new Db instance sharing the current socket connections. Be aware that the new db instances are
|
|
346
341
|
* related in a parent-child relationship to the original instance so that events are correctly emitted on child
|
|
@@ -471,6 +466,7 @@ MongoClient.prototype.isConnected = function(options) {
|
|
|
471
466
|
* @param {array} [options.readPreferenceTags=null] Read preference tags
|
|
472
467
|
* @param {number} [options.numberOfRetries=5] The number of retries for a tailable cursor
|
|
473
468
|
* @param {boolean} [options.auto_reconnect=true] Enable auto reconnecting for single server instances
|
|
469
|
+
* @param {number} [options.minSize] If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections
|
|
474
470
|
* @param {MongoClient~connectCallback} [callback] The command result callback
|
|
475
471
|
* @return {Promise<MongoClient>} returns Promise if no callback passed
|
|
476
472
|
*/
|
|
@@ -486,8 +482,6 @@ MongoClient.connect = function(url, options, callback) {
|
|
|
486
482
|
return mongoClient.connect(callback);
|
|
487
483
|
};
|
|
488
484
|
|
|
489
|
-
define.staticMethod('connect', { callback: true, promise: true });
|
|
490
|
-
|
|
491
485
|
/**
|
|
492
486
|
* Starts a new session on the server
|
|
493
487
|
*
|
|
@@ -495,7 +489,7 @@ define.staticMethod('connect', { callback: true, promise: true });
|
|
|
495
489
|
* @return {ClientSession} the newly established session
|
|
496
490
|
*/
|
|
497
491
|
MongoClient.prototype.startSession = function(options) {
|
|
498
|
-
options =
|
|
492
|
+
options = Object.assign({ explicit: true }, options);
|
|
499
493
|
if (!this.topology) {
|
|
500
494
|
throw new MongoError('Must connect to a server before calling this method');
|
|
501
495
|
}
|
|
@@ -594,6 +588,9 @@ var events = [
|
|
|
594
588
|
'topologyOpening',
|
|
595
589
|
'topologyClosed',
|
|
596
590
|
'topologyDescriptionChanged',
|
|
591
|
+
'commandStarted',
|
|
592
|
+
'commandSucceeded',
|
|
593
|
+
'commandFailed',
|
|
597
594
|
'joined',
|
|
598
595
|
'left',
|
|
599
596
|
'ping',
|
|
@@ -652,11 +649,15 @@ function relayEvents(self, topology) {
|
|
|
652
649
|
'topologyOpening',
|
|
653
650
|
'topologyClosed',
|
|
654
651
|
'topologyDescriptionChanged',
|
|
652
|
+
'commandStarted',
|
|
653
|
+
'commandSucceeded',
|
|
654
|
+
'commandFailed',
|
|
655
655
|
'joined',
|
|
656
656
|
'left',
|
|
657
657
|
'ping',
|
|
658
658
|
'ha'
|
|
659
659
|
];
|
|
660
|
+
|
|
660
661
|
events.forEach(function(event) {
|
|
661
662
|
topology.on(event, function(object1, object2) {
|
|
662
663
|
self.emit(event, object1, object2);
|
|
@@ -684,6 +685,7 @@ function createServer(self, options, callback) {
|
|
|
684
685
|
if (err) return callback(err);
|
|
685
686
|
// Clear out all the collected event listeners
|
|
686
687
|
clearAllEvents(servers[0]);
|
|
688
|
+
|
|
687
689
|
// Relay all the events
|
|
688
690
|
relayEvents(self, servers[0]);
|
|
689
691
|
// Add listeners
|
|
@@ -854,6 +856,10 @@ var connect = function(self, url, options, callback) {
|
|
|
854
856
|
|
|
855
857
|
// Add listeners
|
|
856
858
|
addListeners(self, url);
|
|
859
|
+
|
|
860
|
+
// Propagate the events to the client
|
|
861
|
+
relayEvents(self, url);
|
|
862
|
+
|
|
857
863
|
// Connect
|
|
858
864
|
return url.connect(
|
|
859
865
|
options,
|
package/lib/topologies/mongos.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
MAX_JS_INT = require('../utils').MAX_JS_INT,
|
|
14
|
-
translateOptions = require('../utils').translateOptions,
|
|
15
|
-
filterOptions = require('../utils').filterOptions,
|
|
16
|
-
mergeOptions = require('../utils').mergeOptions;
|
|
3
|
+
const TopologyBase = require('./topology_base').TopologyBase;
|
|
4
|
+
const MongoError = require('mongodb-core').MongoError;
|
|
5
|
+
const CMongos = require('mongodb-core').Mongos;
|
|
6
|
+
const Cursor = require('../cursor');
|
|
7
|
+
const Server = require('./server');
|
|
8
|
+
const Store = require('./topology_base').Store;
|
|
9
|
+
const MAX_JS_INT = require('../utils').MAX_JS_INT;
|
|
10
|
+
const translateOptions = require('../utils').translateOptions;
|
|
11
|
+
const filterOptions = require('../utils').filterOptions;
|
|
12
|
+
const mergeOptions = require('../utils').mergeOptions;
|
|
17
13
|
|
|
18
14
|
/**
|
|
19
15
|
* @fileOverview The **Mongos** class is a class that represents a Mongos Proxy topology and is
|
|
@@ -58,7 +54,8 @@ var legalOptionNames = [
|
|
|
58
54
|
'promoteLongs',
|
|
59
55
|
'promoteValues',
|
|
60
56
|
'promoteBuffers',
|
|
61
|
-
'promiseLibrary'
|
|
57
|
+
'promiseLibrary',
|
|
58
|
+
'monitorCommands'
|
|
62
59
|
];
|
|
63
60
|
|
|
64
61
|
/**
|
|
@@ -89,6 +86,7 @@ var legalOptionNames = [
|
|
|
89
86
|
* @param {number} [options.socketOptions.connectTimeoutMS=0] TCP Connection timeout setting
|
|
90
87
|
* @param {number} [options.socketOptions.socketTimeoutMS=0] TCP Socket timeout setting
|
|
91
88
|
* @param {boolean} [options.domainsEnabled=false] Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit.
|
|
89
|
+
* @param {boolean} [options.monitorCommands=false] Enable command monitoring for this topology
|
|
92
90
|
* @fires Mongos#connect
|
|
93
91
|
* @fires Mongos#ha
|
|
94
92
|
* @fires Mongos#joined
|
|
@@ -99,6 +97,9 @@ var legalOptionNames = [
|
|
|
99
97
|
* @fires Mongos#error
|
|
100
98
|
* @fires Mongos#timeout
|
|
101
99
|
* @fires Mongos#parseError
|
|
100
|
+
* @fires Mongos#commandStarted
|
|
101
|
+
* @fires Mongos#commandSucceeded
|
|
102
|
+
* @fires Mongos#commandFailed
|
|
102
103
|
* @property {string} parserType the parser type used (c++ or js).
|
|
103
104
|
* @return {Mongos} a Mongos instance.
|
|
104
105
|
*/
|
|
@@ -149,7 +150,9 @@ class Mongos extends TopologyBase {
|
|
|
149
150
|
cursorFactory: Cursor,
|
|
150
151
|
reconnect: reconnect,
|
|
151
152
|
emitError: typeof options.emitError === 'boolean' ? options.emitError : true,
|
|
152
|
-
size: typeof options.poolSize === 'number' ? options.poolSize : 5
|
|
153
|
+
size: typeof options.poolSize === 'number' ? options.poolSize : 5,
|
|
154
|
+
monitorCommands:
|
|
155
|
+
typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false
|
|
153
156
|
}
|
|
154
157
|
);
|
|
155
158
|
|
|
@@ -300,7 +303,10 @@ class Mongos extends TopologyBase {
|
|
|
300
303
|
'serverClosed',
|
|
301
304
|
'topologyOpening',
|
|
302
305
|
'topologyClosed',
|
|
303
|
-
'topologyDescriptionChanged'
|
|
306
|
+
'topologyDescriptionChanged',
|
|
307
|
+
'commandStarted',
|
|
308
|
+
'commandSucceeded',
|
|
309
|
+
'commandFailed'
|
|
304
310
|
];
|
|
305
311
|
events.forEach(function(e) {
|
|
306
312
|
self.s.coreTopology.removeAllListeners(e);
|
|
@@ -316,6 +322,9 @@ class Mongos extends TopologyBase {
|
|
|
316
322
|
self.s.coreTopology.on('topologyOpening', relay('topologyOpening'));
|
|
317
323
|
self.s.coreTopology.on('topologyClosed', relay('topologyClosed'));
|
|
318
324
|
self.s.coreTopology.on('topologyDescriptionChanged', relay('topologyDescriptionChanged'));
|
|
325
|
+
self.s.coreTopology.on('commandStarted', relay('commandStarted'));
|
|
326
|
+
self.s.coreTopology.on('commandSucceeded', relay('commandSucceeded'));
|
|
327
|
+
self.s.coreTopology.on('commandFailed', relay('commandFailed'));
|
|
319
328
|
|
|
320
329
|
// Set up listeners
|
|
321
330
|
self.s.coreTopology.once('timeout', connectErrorHandler('timeout'));
|
|
@@ -341,30 +350,6 @@ Object.defineProperty(Mongos.prototype, 'haInterval', {
|
|
|
341
350
|
}
|
|
342
351
|
});
|
|
343
352
|
|
|
344
|
-
const define = (Mongos.define = new Define('Mongos', Mongos, false));
|
|
345
|
-
define.classMethod('capabilities', {
|
|
346
|
-
callback: false,
|
|
347
|
-
promise: false,
|
|
348
|
-
returns: [ServerCapabilities]
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
define.classMethod('command', { callback: true, promise: false });
|
|
352
|
-
define.classMethod('insert', { callback: true, promise: false });
|
|
353
|
-
define.classMethod('update', { callback: true, promise: false });
|
|
354
|
-
define.classMethod('remove', { callback: true, promise: false });
|
|
355
|
-
define.classMethod('isConnected', { callback: false, promise: false, returns: [Boolean] });
|
|
356
|
-
define.classMethod('isDestroyed', { callback: false, promise: false, returns: [Boolean] });
|
|
357
|
-
define.classMethod('cursor', {
|
|
358
|
-
callback: false,
|
|
359
|
-
promise: false,
|
|
360
|
-
returns: [Cursor, AggregationCursor, CommandCursor]
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
define.classMethod('close', { callback: false, promise: false });
|
|
364
|
-
define.classMethod('auth', { callback: true, promise: false });
|
|
365
|
-
define.classMethod('logout', { callback: true, promise: false });
|
|
366
|
-
define.classMethod('connections', { callback: false, promise: false, returns: [Array] });
|
|
367
|
-
|
|
368
353
|
/**
|
|
369
354
|
* A mongos connect event, used to verify that the connection is up and running
|
|
370
355
|
*
|
|
@@ -443,4 +428,25 @@ define.classMethod('connections', { callback: false, promise: false, returns: [A
|
|
|
443
428
|
* @type {object}
|
|
444
429
|
*/
|
|
445
430
|
|
|
431
|
+
/**
|
|
432
|
+
* An event emitted indicating a command was started, if command monitoring is enabled
|
|
433
|
+
*
|
|
434
|
+
* @event Mongos#commandStarted
|
|
435
|
+
* @type {object}
|
|
436
|
+
*/
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* An event emitted indicating a command succeeded, if command monitoring is enabled
|
|
440
|
+
*
|
|
441
|
+
* @event Mongos#commandSucceeded
|
|
442
|
+
* @type {object}
|
|
443
|
+
*/
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* An event emitted indicating a command failed, if command monitoring is enabled
|
|
447
|
+
*
|
|
448
|
+
* @event Mongos#commandFailed
|
|
449
|
+
* @type {object}
|
|
450
|
+
*/
|
|
451
|
+
|
|
446
452
|
module.exports = Mongos;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
MAX_JS_INT = require('../utils').MAX_JS_INT,
|
|
14
|
-
translateOptions = require('../utils').translateOptions,
|
|
15
|
-
filterOptions = require('../utils').filterOptions,
|
|
16
|
-
mergeOptions = require('../utils').mergeOptions;
|
|
3
|
+
const Server = require('./server');
|
|
4
|
+
const Cursor = require('../cursor');
|
|
5
|
+
const MongoError = require('mongodb-core').MongoError;
|
|
6
|
+
const TopologyBase = require('./topology_base').TopologyBase;
|
|
7
|
+
const Store = require('./topology_base').Store;
|
|
8
|
+
const CReplSet = require('mongodb-core').ReplSet;
|
|
9
|
+
const MAX_JS_INT = require('../utils').MAX_JS_INT;
|
|
10
|
+
const translateOptions = require('../utils').translateOptions;
|
|
11
|
+
const filterOptions = require('../utils').filterOptions;
|
|
12
|
+
const mergeOptions = require('../utils').mergeOptions;
|
|
17
13
|
|
|
18
14
|
/**
|
|
19
15
|
* @fileOverview The **ReplSet** class is a class that represents a Replicaset topology and is
|
|
@@ -66,7 +62,8 @@ var legalOptionNames = [
|
|
|
66
62
|
'promoteBuffers',
|
|
67
63
|
'maxStalenessSeconds',
|
|
68
64
|
'promiseLibrary',
|
|
69
|
-
'minSize'
|
|
65
|
+
'minSize',
|
|
66
|
+
'monitorCommands'
|
|
70
67
|
];
|
|
71
68
|
|
|
72
69
|
/**
|
|
@@ -100,6 +97,7 @@ var legalOptionNames = [
|
|
|
100
97
|
* @param {number} [options.socketOptions.socketTimeoutMS=0] TCP Socket timeout setting
|
|
101
98
|
* @param {boolean} [options.domainsEnabled=false] Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit.
|
|
102
99
|
* @param {number} [options.maxStalenessSeconds=undefined] The max staleness to secondary reads (values under 10 seconds cannot be guaranteed);
|
|
100
|
+
* @param {boolean} [options.monitorCommands=false] Enable command monitoring for this topology
|
|
103
101
|
* @fires ReplSet#connect
|
|
104
102
|
* @fires ReplSet#ha
|
|
105
103
|
* @fires ReplSet#joined
|
|
@@ -110,6 +108,9 @@ var legalOptionNames = [
|
|
|
110
108
|
* @fires ReplSet#error
|
|
111
109
|
* @fires ReplSet#timeout
|
|
112
110
|
* @fires ReplSet#parseError
|
|
111
|
+
* @fires ReplSet#commandStarted
|
|
112
|
+
* @fires ReplSet#commandSucceeded
|
|
113
|
+
* @fires ReplSet#commandFailed
|
|
113
114
|
* @property {string} parserType the parser type used (c++ or js).
|
|
114
115
|
* @return {ReplSet} a ReplSet instance.
|
|
115
116
|
*/
|
|
@@ -156,7 +157,9 @@ class ReplSet extends TopologyBase {
|
|
|
156
157
|
cursorFactory: Cursor,
|
|
157
158
|
reconnect: false,
|
|
158
159
|
emitError: typeof options.emitError === 'boolean' ? options.emitError : true,
|
|
159
|
-
size: typeof options.poolSize === 'number' ? options.poolSize : 5
|
|
160
|
+
size: typeof options.poolSize === 'number' ? options.poolSize : 5,
|
|
161
|
+
monitorCommands:
|
|
162
|
+
typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false
|
|
160
163
|
}
|
|
161
164
|
);
|
|
162
165
|
|
|
@@ -260,6 +263,9 @@ class ReplSet extends TopologyBase {
|
|
|
260
263
|
'topologyOpening',
|
|
261
264
|
'topologyClosed',
|
|
262
265
|
'topologyDescriptionChanged',
|
|
266
|
+
'commandStarted',
|
|
267
|
+
'commandSucceeded',
|
|
268
|
+
'commandFailed',
|
|
263
269
|
'joined',
|
|
264
270
|
'left',
|
|
265
271
|
'ping',
|
|
@@ -310,6 +316,9 @@ class ReplSet extends TopologyBase {
|
|
|
310
316
|
self.s.coreTopology.on('topologyOpening', relay('topologyOpening'));
|
|
311
317
|
self.s.coreTopology.on('topologyClosed', relay('topologyClosed'));
|
|
312
318
|
self.s.coreTopology.on('topologyDescriptionChanged', relay('topologyDescriptionChanged'));
|
|
319
|
+
self.s.coreTopology.on('commandStarted', relay('commandStarted'));
|
|
320
|
+
self.s.coreTopology.on('commandSucceeded', relay('commandSucceeded'));
|
|
321
|
+
self.s.coreTopology.on('commandFailed', relay('commandFailed'));
|
|
313
322
|
|
|
314
323
|
self.s.coreTopology.on('fullsetup', function() {
|
|
315
324
|
self.emit('fullsetup', self, self);
|
|
@@ -386,29 +395,6 @@ Object.defineProperty(ReplSet.prototype, 'haInterval', {
|
|
|
386
395
|
}
|
|
387
396
|
});
|
|
388
397
|
|
|
389
|
-
const define = (ReplSet.define = new Define('ReplSet', ReplSet, false));
|
|
390
|
-
define.classMethod('capabilities', {
|
|
391
|
-
callback: false,
|
|
392
|
-
promise: false,
|
|
393
|
-
returns: [ServerCapabilities]
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
define.classMethod('command', { callback: true, promise: false });
|
|
397
|
-
define.classMethod('insert', { callback: true, promise: false });
|
|
398
|
-
define.classMethod('update', { callback: true, promise: false });
|
|
399
|
-
define.classMethod('remove', { callback: true, promise: false });
|
|
400
|
-
define.classMethod('isConnected', { callback: false, promise: false, returns: [Boolean] });
|
|
401
|
-
define.classMethod('cursor', {
|
|
402
|
-
callback: false,
|
|
403
|
-
promise: false,
|
|
404
|
-
returns: [Cursor, AggregationCursor, CommandCursor]
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
define.classMethod('close', { callback: false, promise: false });
|
|
408
|
-
define.classMethod('auth', { callback: true, promise: false });
|
|
409
|
-
define.classMethod('logout', { callback: true, promise: false });
|
|
410
|
-
define.classMethod('connections', { callback: false, promise: false, returns: [Array] });
|
|
411
|
-
|
|
412
398
|
/**
|
|
413
399
|
* A replset connect event, used to verify that the connection is up and running
|
|
414
400
|
*
|
|
@@ -487,4 +473,25 @@ define.classMethod('connections', { callback: false, promise: false, returns: [A
|
|
|
487
473
|
* @type {object}
|
|
488
474
|
*/
|
|
489
475
|
|
|
476
|
+
/**
|
|
477
|
+
* An event emitted indicating a command was started, if command monitoring is enabled
|
|
478
|
+
*
|
|
479
|
+
* @event ReplSet#commandStarted
|
|
480
|
+
* @type {object}
|
|
481
|
+
*/
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* An event emitted indicating a command succeeded, if command monitoring is enabled
|
|
485
|
+
*
|
|
486
|
+
* @event ReplSet#commandSucceeded
|
|
487
|
+
* @type {object}
|
|
488
|
+
*/
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* An event emitted indicating a command failed, if command monitoring is enabled
|
|
492
|
+
*
|
|
493
|
+
* @event ReplSet#commandFailed
|
|
494
|
+
* @type {object}
|
|
495
|
+
*/
|
|
496
|
+
|
|
490
497
|
module.exports = ReplSet;
|
package/lib/topologies/server.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
MAX_JS_INT = require('../utils').MAX_JS_INT,
|
|
13
|
-
translateOptions = require('../utils').translateOptions,
|
|
14
|
-
filterOptions = require('../utils').filterOptions,
|
|
15
|
-
mergeOptions = require('../utils').mergeOptions;
|
|
3
|
+
const CServer = require('mongodb-core').Server;
|
|
4
|
+
const Cursor = require('../cursor');
|
|
5
|
+
const TopologyBase = require('./topology_base').TopologyBase;
|
|
6
|
+
const Store = require('./topology_base').Store;
|
|
7
|
+
const MongoError = require('mongodb-core').MongoError;
|
|
8
|
+
const MAX_JS_INT = require('../utils').MAX_JS_INT;
|
|
9
|
+
const translateOptions = require('../utils').translateOptions;
|
|
10
|
+
const filterOptions = require('../utils').filterOptions;
|
|
11
|
+
const mergeOptions = require('../utils').mergeOptions;
|
|
16
12
|
|
|
17
13
|
/**
|
|
18
14
|
* @fileOverview The **Server** class is a class that represents a single server topology and is
|
|
@@ -61,7 +57,8 @@ var legalOptionNames = [
|
|
|
61
57
|
'promoteValues',
|
|
62
58
|
'promoteBuffers',
|
|
63
59
|
'compression',
|
|
64
|
-
'promiseLibrary'
|
|
60
|
+
'promiseLibrary',
|
|
61
|
+
'monitorCommands'
|
|
65
62
|
];
|
|
66
63
|
|
|
67
64
|
/**
|
|
@@ -95,12 +92,16 @@ var legalOptionNames = [
|
|
|
95
92
|
* @param {number} [options.monitoring=true] Triggers the server instance to call ismaster
|
|
96
93
|
* @param {number} [options.haInterval=10000] The interval of calling ismaster when monitoring is enabled.
|
|
97
94
|
* @param {boolean} [options.domainsEnabled=false] Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit.
|
|
95
|
+
* @param {boolean} [options.monitorCommands=false] Enable command monitoring for this topology
|
|
98
96
|
* @fires Server#connect
|
|
99
97
|
* @fires Server#close
|
|
100
98
|
* @fires Server#error
|
|
101
99
|
* @fires Server#timeout
|
|
102
100
|
* @fires Server#parseError
|
|
103
101
|
* @fires Server#reconnect
|
|
102
|
+
* @fires Server#commandStarted
|
|
103
|
+
* @fires Server#commandSucceeded
|
|
104
|
+
* @fires Server#commandFailed
|
|
104
105
|
* @property {string} parserType the parser type used (c++ or js).
|
|
105
106
|
* @return {Server} a Server instance.
|
|
106
107
|
*/
|
|
@@ -149,7 +150,9 @@ class Server extends TopologyBase {
|
|
|
149
150
|
cursorFactory: Cursor,
|
|
150
151
|
reconnect: reconnect,
|
|
151
152
|
emitError: typeof options.emitError === 'boolean' ? options.emitError : true,
|
|
152
|
-
size: typeof options.poolSize === 'number' ? options.poolSize : 5
|
|
153
|
+
size: typeof options.poolSize === 'number' ? options.poolSize : 5,
|
|
154
|
+
monitorCommands:
|
|
155
|
+
typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false
|
|
153
156
|
}
|
|
154
157
|
);
|
|
155
158
|
|
|
@@ -321,7 +324,10 @@ class Server extends TopologyBase {
|
|
|
321
324
|
'serverClosed',
|
|
322
325
|
'topologyOpening',
|
|
323
326
|
'topologyClosed',
|
|
324
|
-
'topologyDescriptionChanged'
|
|
327
|
+
'topologyDescriptionChanged',
|
|
328
|
+
'commandStarted',
|
|
329
|
+
'commandSucceeded',
|
|
330
|
+
'commandFailed'
|
|
325
331
|
].forEach(function(e) {
|
|
326
332
|
self.s.coreTopology.removeAllListeners(e);
|
|
327
333
|
});
|
|
@@ -345,6 +351,9 @@ class Server extends TopologyBase {
|
|
|
345
351
|
self.s.coreTopology.on('topologyOpening', relay('topologyOpening'));
|
|
346
352
|
self.s.coreTopology.on('topologyClosed', relay('topologyClosed'));
|
|
347
353
|
self.s.coreTopology.on('topologyDescriptionChanged', relay('topologyDescriptionChanged'));
|
|
354
|
+
self.s.coreTopology.on('commandStarted', relay('commandStarted'));
|
|
355
|
+
self.s.coreTopology.on('commandSucceeded', relay('commandSucceeded'));
|
|
356
|
+
self.s.coreTopology.on('commandFailed', relay('commandFailed'));
|
|
348
357
|
self.s.coreTopology.on('attemptReconnect', relay('attemptReconnect'));
|
|
349
358
|
self.s.coreTopology.on('monitoring', relay('monitoring'));
|
|
350
359
|
|
|
@@ -381,30 +390,6 @@ Object.defineProperty(Server.prototype, 'port', {
|
|
|
381
390
|
}
|
|
382
391
|
});
|
|
383
392
|
|
|
384
|
-
const define = (Server.define = new Define('Server', Server, false));
|
|
385
|
-
define.classMethod('capabilities', {
|
|
386
|
-
callback: false,
|
|
387
|
-
promise: false,
|
|
388
|
-
returns: [ServerCapabilities]
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
define.classMethod('command', { callback: true, promise: false });
|
|
392
|
-
define.classMethod('insert', { callback: true, promise: false });
|
|
393
|
-
define.classMethod('update', { callback: true, promise: false });
|
|
394
|
-
define.classMethod('remove', { callback: true, promise: false });
|
|
395
|
-
define.classMethod('isConnected', { callback: false, promise: false, returns: [Boolean] });
|
|
396
|
-
define.classMethod('isDestroyed', { callback: false, promise: false, returns: [Boolean] });
|
|
397
|
-
define.classMethod('cursor', {
|
|
398
|
-
callback: false,
|
|
399
|
-
promise: false,
|
|
400
|
-
returns: [Cursor, AggregationCursor, CommandCursor]
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
define.classMethod('close', { callback: false, promise: false });
|
|
404
|
-
define.classMethod('auth', { callback: true, promise: false });
|
|
405
|
-
define.classMethod('logout', { callback: true, promise: false });
|
|
406
|
-
define.classMethod('connections', { callback: false, promise: false, returns: [Array] });
|
|
407
|
-
|
|
408
393
|
/**
|
|
409
394
|
* Server connect event
|
|
410
395
|
*
|
|
@@ -447,4 +432,25 @@ define.classMethod('connections', { callback: false, promise: false, returns: [A
|
|
|
447
432
|
* @type {object}
|
|
448
433
|
*/
|
|
449
434
|
|
|
435
|
+
/**
|
|
436
|
+
* An event emitted indicating a command was started, if command monitoring is enabled
|
|
437
|
+
*
|
|
438
|
+
* @event Server#commandStarted
|
|
439
|
+
* @type {object}
|
|
440
|
+
*/
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* An event emitted indicating a command succeeded, if command monitoring is enabled
|
|
444
|
+
*
|
|
445
|
+
* @event Server#commandSucceeded
|
|
446
|
+
* @type {object}
|
|
447
|
+
*/
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* An event emitted indicating a command failed, if command monitoring is enabled
|
|
451
|
+
*
|
|
452
|
+
* @event Server#commandFailed
|
|
453
|
+
* @type {object}
|
|
454
|
+
*/
|
|
455
|
+
|
|
450
456
|
module.exports = Server;
|
|
@@ -394,11 +394,9 @@ class TopologyBase extends EventEmitter {
|
|
|
394
394
|
}
|
|
395
395
|
|
|
396
396
|
close(forceClosed) {
|
|
397
|
-
// If we have sessions, we want to
|
|
398
|
-
// and then
|
|
399
|
-
// when they emit their `ended` events.
|
|
397
|
+
// If we have sessions, we want to individually move them to the session pool,
|
|
398
|
+
// and then send a single endSessions call.
|
|
400
399
|
if (this.s.sessions.length) {
|
|
401
|
-
this.endSessions(this.s.sessions.map(session => session.id));
|
|
402
400
|
this.s.sessions.forEach(session => session.endSession({ skipCommand: true }));
|
|
403
401
|
}
|
|
404
402
|
|
package/lib/url_parser.js
CHANGED
|
@@ -63,6 +63,16 @@ module.exports = function(url, options, callback) {
|
|
|
63
63
|
let connectionString = connectionStrings.join(',') + '/';
|
|
64
64
|
let connectionStringOptions = [];
|
|
65
65
|
|
|
66
|
+
// Add the default database if needed
|
|
67
|
+
if (result.path) {
|
|
68
|
+
let defaultDb = result.path.slice(1);
|
|
69
|
+
if (defaultDb.indexOf('?') !== -1) {
|
|
70
|
+
defaultDb = defaultDb.slice(0, defaultDb.indexOf('?'));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
connectionString += defaultDb;
|
|
74
|
+
}
|
|
75
|
+
|
|
66
76
|
// Default to SSL true
|
|
67
77
|
if (!options.ssl && !result.search) {
|
|
68
78
|
connectionStringOptions.push('ssl=true');
|