mongodb 3.5.6 → 3.5.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.
- package/HISTORY.md +11 -0
- package/lib/change_stream.js +12 -13
- package/lib/core/sessions.js +14 -5
- package/lib/mongo_client.js +13 -2
- package/lib/operations/db_ops.js +0 -361
- package/package.json +3 -3
package/HISTORY.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
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.5.7"></a>
|
|
6
|
+
## [3.5.7](https://github.com/mongodb/node-mongodb-native/compare/v3.5.6...v3.5.7) (2020-04-29)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* limit growth of server sessions through lazy acquisition ([3d05a6d](https://github.com/mongodb/node-mongodb-native/commit/3d05a6d))
|
|
12
|
+
* remove circular dependency warnings on node 14 ([56a1b8a](https://github.com/mongodb/node-mongodb-native/commit/56a1b8a))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
5
16
|
<a name="3.5.6"></a>
|
|
6
17
|
## [3.5.6](https://github.com/mongodb/node-mongodb-native/compare/v3.5.5...v3.5.6) (2020-04-14)
|
|
7
18
|
|
package/lib/change_stream.js
CHANGED
|
@@ -6,6 +6,7 @@ const MongoError = require('./core').MongoError;
|
|
|
6
6
|
const Cursor = require('./cursor');
|
|
7
7
|
const relayEvents = require('./core/utils').relayEvents;
|
|
8
8
|
const maxWireVersion = require('./core/utils').maxWireVersion;
|
|
9
|
+
const maybePromise = require('./utils').maybePromise;
|
|
9
10
|
const AggregateOperation = require('./operations/aggregate');
|
|
10
11
|
|
|
11
12
|
const CHANGE_STREAM_OPTIONS = ['resumeAfter', 'startAfter', 'startAtOperationTime', 'fullDocument'];
|
|
@@ -124,10 +125,10 @@ class ChangeStream extends EventEmitter {
|
|
|
124
125
|
* @function ChangeStream.prototype.hasNext
|
|
125
126
|
* @param {ChangeStream~resultCallback} [callback] The result callback.
|
|
126
127
|
* @throws {MongoError}
|
|
127
|
-
* @
|
|
128
|
+
* @returns {Promise|void} returns Promise if no callback passed
|
|
128
129
|
*/
|
|
129
130
|
hasNext(callback) {
|
|
130
|
-
return this.cursor.hasNext(
|
|
131
|
+
return maybePromise(this.parent, callback, cb => this.cursor.hasNext(cb));
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
/**
|
|
@@ -135,19 +136,17 @@ class ChangeStream extends EventEmitter {
|
|
|
135
136
|
* @function ChangeStream.prototype.next
|
|
136
137
|
* @param {ChangeStream~resultCallback} [callback] The result callback.
|
|
137
138
|
* @throws {MongoError}
|
|
138
|
-
* @
|
|
139
|
+
* @returns {Promise|void} returns Promise if no callback passed
|
|
139
140
|
*/
|
|
140
141
|
next(callback) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
.then(change => processNewChange({ changeStream: self, change, callback }))
|
|
150
|
-
.catch(error => processNewChange({ changeStream: self, error, callback }));
|
|
142
|
+
return maybePromise(this.parent, callback, cb => {
|
|
143
|
+
if (this.isClosed()) {
|
|
144
|
+
return cb(new Error('Change Stream is not open.'));
|
|
145
|
+
}
|
|
146
|
+
this.cursor.next((error, change) => {
|
|
147
|
+
processNewChange({ changeStream: this, error, change, callback: cb });
|
|
148
|
+
});
|
|
149
|
+
});
|
|
151
150
|
}
|
|
152
151
|
|
|
153
152
|
/**
|
package/lib/core/sessions.js
CHANGED
|
@@ -46,6 +46,8 @@ function assertAlive(session, callback) {
|
|
|
46
46
|
* @typedef {Object} SessionId
|
|
47
47
|
*/
|
|
48
48
|
|
|
49
|
+
const kServerSession = Symbol('serverSession');
|
|
50
|
+
|
|
49
51
|
/**
|
|
50
52
|
* A class representing a client session on the server
|
|
51
53
|
* WARNING: not meant to be instantiated directly.
|
|
@@ -79,8 +81,8 @@ class ClientSession extends EventEmitter {
|
|
|
79
81
|
this.topology = topology;
|
|
80
82
|
this.sessionPool = sessionPool;
|
|
81
83
|
this.hasEnded = false;
|
|
82
|
-
this.serverSession = sessionPool.acquire();
|
|
83
84
|
this.clientOptions = clientOptions;
|
|
85
|
+
this[kServerSession] = undefined;
|
|
84
86
|
|
|
85
87
|
this.supports = {
|
|
86
88
|
causalConsistency:
|
|
@@ -104,6 +106,14 @@ class ClientSession extends EventEmitter {
|
|
|
104
106
|
return this.serverSession.id;
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
get serverSession() {
|
|
110
|
+
if (this[kServerSession] == null) {
|
|
111
|
+
this[kServerSession] = this.sessionPool.acquire();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return this[kServerSession];
|
|
115
|
+
}
|
|
116
|
+
|
|
107
117
|
/**
|
|
108
118
|
* Ends this session on the server
|
|
109
119
|
*
|
|
@@ -125,7 +135,7 @@ class ClientSession extends EventEmitter {
|
|
|
125
135
|
|
|
126
136
|
// release the server session back to the pool
|
|
127
137
|
this.sessionPool.release(this.serverSession);
|
|
128
|
-
this
|
|
138
|
+
this[kServerSession] = undefined;
|
|
129
139
|
|
|
130
140
|
// mark the session as ended, and emit a signal
|
|
131
141
|
this.hasEnded = true;
|
|
@@ -692,13 +702,12 @@ function commandSupportsReadConcern(command, options) {
|
|
|
692
702
|
* @return {MongoError|null} An error, if some error condition was met
|
|
693
703
|
*/
|
|
694
704
|
function applySession(session, command, options) {
|
|
695
|
-
|
|
696
|
-
if (serverSession == null) {
|
|
705
|
+
if (session.hasEnded) {
|
|
697
706
|
// TODO: merge this with `assertAlive`, did not want to throw a try/catch here
|
|
698
707
|
return new MongoError('Cannot use a session that has ended');
|
|
699
708
|
}
|
|
700
709
|
|
|
701
|
-
|
|
710
|
+
const serverSession = session.serverSession;
|
|
702
711
|
serverSession.lastUse = Date.now();
|
|
703
712
|
command.lsid = serverSession.id;
|
|
704
713
|
|
package/lib/mongo_client.js
CHANGED
|
@@ -143,6 +143,9 @@ const validOptions = require('./operations/connect').validOptions;
|
|
|
143
143
|
* @param {number} [options.minSize] If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections
|
|
144
144
|
* @param {boolean} [options.useNewUrlParser=true] Determines whether or not to use the new url parser. Enables the new, spec-compliant, url parser shipped in the core driver. This url parser fixes a number of problems with the original parser, and aims to outright replace that parser in the near future. Defaults to true, and must be explicitly set to false to use the legacy url parser.
|
|
145
145
|
* @param {boolean} [options.useUnifiedTopology] Enables the new unified topology layer
|
|
146
|
+
* @param {Number} [options.localThresholdMS=15] **Only applies to the unified topology** The size of the latency window for selecting among multiple suitable servers
|
|
147
|
+
* @param {Number} [options.serverSelectionTimeoutMS=30000] **Only applies to the unified topology** How long to block for server selection before throwing an error
|
|
148
|
+
* @param {Number} [options.heartbeatFrequencyMS=10000] **Only applies to the unified topology** The frequency with which topology updates are scheduled
|
|
146
149
|
* @param {AutoEncrypter~AutoEncryptionOptions} [options.autoEncryption] Optionally enable client side auto encryption
|
|
147
150
|
* @param {DriverInfoOptions} [options.driverInfo] Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver
|
|
148
151
|
* @param {MongoClient~connectCallback} [callback] The command result callback
|
|
@@ -344,7 +347,7 @@ MongoClient.prototype.isConnected = function(options) {
|
|
|
344
347
|
* @param {object} [options] Optional settings
|
|
345
348
|
* @param {number} [options.poolSize=5] The maximum size of the individual server pool
|
|
346
349
|
* @param {boolean} [options.ssl=false] Enable SSL connection. *deprecated* use `tls` variants
|
|
347
|
-
* @param {boolean} [options.sslValidate=false] Validate mongod server certificate against Certificate Authority
|
|
350
|
+
* @param {boolean} [options.sslValidate=false] Validate mongod server certificate against Certificate Authority
|
|
348
351
|
* @param {buffer} [options.sslCA=undefined] SSL Certificate store binary buffer *deprecated* use `tls` variants
|
|
349
352
|
* @param {buffer} [options.sslCert=undefined] SSL Certificate binary buffer *deprecated* use `tls` variants
|
|
350
353
|
* @param {buffer} [options.sslKey=undefined] SSL Key file binary buffer *deprecated* use `tls` variants
|
|
@@ -361,7 +364,7 @@ MongoClient.prototype.isConnected = function(options) {
|
|
|
361
364
|
* @param {boolean} [options.autoReconnect=true] Enable autoReconnect for single server instances
|
|
362
365
|
* @param {boolean} [options.noDelay=true] TCP Connection no delay
|
|
363
366
|
* @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled
|
|
364
|
-
* @param {
|
|
367
|
+
* @param {number} [options.keepAliveInitialDelay=30000] The number of milliseconds to wait before initiating keepAlive on the TCP socket
|
|
365
368
|
* @param {number} [options.connectTimeoutMS=10000] How long to wait for a connection to be established before timing out
|
|
366
369
|
* @param {number} [options.socketTimeoutMS=360000] How long a send or receive on a socket can take before timing out
|
|
367
370
|
* @param {number} [options.family] Version of IP stack. Can be 4, 6 or null (default).
|
|
@@ -405,7 +408,15 @@ MongoClient.prototype.isConnected = function(options) {
|
|
|
405
408
|
* @param {array} [options.readPreferenceTags] Read preference tags
|
|
406
409
|
* @param {number} [options.numberOfRetries=5] The number of retries for a tailable cursor
|
|
407
410
|
* @param {boolean} [options.auto_reconnect=true] Enable auto reconnecting for single server instances
|
|
411
|
+
* @param {boolean} [options.monitorCommands=false] Enable command monitoring for this client
|
|
408
412
|
* @param {number} [options.minSize] If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections
|
|
413
|
+
* @param {boolean} [options.useNewUrlParser=true] Determines whether or not to use the new url parser. Enables the new, spec-compliant, url parser shipped in the core driver. This url parser fixes a number of problems with the original parser, and aims to outright replace that parser in the near future. Defaults to true, and must be explicitly set to false to use the legacy url parser.
|
|
414
|
+
* @param {boolean} [options.useUnifiedTopology] Enables the new unified topology layer
|
|
415
|
+
* @param {Number} [options.localThresholdMS=15] **Only applies to the unified topology** The size of the latency window for selecting among multiple suitable servers
|
|
416
|
+
* @param {Number} [options.serverSelectionTimeoutMS=30000] **Only applies to the unified topology** How long to block for server selection before throwing an error
|
|
417
|
+
* @param {Number} [options.heartbeatFrequencyMS=10000] **Only applies to the unified topology** The frequency with which topology updates are scheduled
|
|
418
|
+
* @param {AutoEncrypter~AutoEncryptionOptions} [options.autoEncryption] Optionally enable client side auto encryption
|
|
419
|
+
* @param {DriverInfoOptions} [options.driverInfo] Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver
|
|
409
420
|
* @param {MongoClient~connectCallback} [callback] The command result callback
|
|
410
421
|
* @return {Promise<MongoClient>} returns Promise if no callback passed
|
|
411
422
|
*/
|
package/lib/operations/db_ops.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
const applyWriteConcern = require('../utils').applyWriteConcern;
|
|
4
4
|
const Code = require('../core').BSON.Code;
|
|
5
5
|
const resolveReadPreference = require('../utils').resolveReadPreference;
|
|
6
|
-
const crypto = require('crypto');
|
|
7
6
|
const debugOptions = require('../utils').debugOptions;
|
|
8
7
|
const handleCallback = require('../utils').handleCallback;
|
|
9
8
|
const MongoError = require('../core').MongoError;
|
|
@@ -13,26 +12,6 @@ const toError = require('../utils').toError;
|
|
|
13
12
|
const CONSTANTS = require('../constants');
|
|
14
13
|
const MongoDBNamespace = require('../utils').MongoDBNamespace;
|
|
15
14
|
|
|
16
|
-
const count = require('./collection_ops').count;
|
|
17
|
-
const findOne = require('./collection_ops').findOne;
|
|
18
|
-
const remove = require('./collection_ops').remove;
|
|
19
|
-
const updateOne = require('./collection_ops').updateOne;
|
|
20
|
-
|
|
21
|
-
let collection;
|
|
22
|
-
function loadCollection() {
|
|
23
|
-
if (!collection) {
|
|
24
|
-
collection = require('../collection');
|
|
25
|
-
}
|
|
26
|
-
return collection;
|
|
27
|
-
}
|
|
28
|
-
let db;
|
|
29
|
-
function loadDb() {
|
|
30
|
-
if (!db) {
|
|
31
|
-
db = require('../db');
|
|
32
|
-
}
|
|
33
|
-
return db;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
15
|
const debugFields = [
|
|
37
16
|
'authSource',
|
|
38
17
|
'w',
|
|
@@ -55,113 +34,6 @@ const debugFields = [
|
|
|
55
34
|
'noListener'
|
|
56
35
|
];
|
|
57
36
|
|
|
58
|
-
/**
|
|
59
|
-
* Add a user to the database.
|
|
60
|
-
* @method
|
|
61
|
-
* @param {Db} db The Db instance on which to add a user.
|
|
62
|
-
* @param {string} username The username.
|
|
63
|
-
* @param {string} password The password.
|
|
64
|
-
* @param {object} [options] Optional settings. See Db.prototype.addUser for a list of options.
|
|
65
|
-
* @param {Db~resultCallback} [callback] The command result callback
|
|
66
|
-
*/
|
|
67
|
-
function addUser(db, username, password, options, callback) {
|
|
68
|
-
let Db = loadDb();
|
|
69
|
-
|
|
70
|
-
// Did the user destroy the topology
|
|
71
|
-
if (db.serverConfig && db.serverConfig.isDestroyed())
|
|
72
|
-
return callback(new MongoError('topology was destroyed'));
|
|
73
|
-
// Attempt to execute auth command
|
|
74
|
-
executeAuthCreateUserCommand(db, username, password, options, (err, r) => {
|
|
75
|
-
// We need to perform the backward compatible insert operation
|
|
76
|
-
if (err && err.code === -5000) {
|
|
77
|
-
const finalOptions = applyWriteConcern(Object.assign({}, options), { db }, options);
|
|
78
|
-
|
|
79
|
-
// Use node md5 generator
|
|
80
|
-
const md5 = crypto.createHash('md5');
|
|
81
|
-
// Generate keys used for authentication
|
|
82
|
-
md5.update(username + ':mongo:' + password);
|
|
83
|
-
const userPassword = md5.digest('hex');
|
|
84
|
-
|
|
85
|
-
// If we have another db set
|
|
86
|
-
const dbToUse = options.dbName ? new Db(options.dbName, db.s.topology, db.s.options) : db;
|
|
87
|
-
|
|
88
|
-
// Fetch a user collection
|
|
89
|
-
const collection = dbToUse.collection(CONSTANTS.SYSTEM_USER_COLLECTION);
|
|
90
|
-
|
|
91
|
-
// Check if we are inserting the first user
|
|
92
|
-
count(collection, {}, finalOptions, (err, count) => {
|
|
93
|
-
// We got an error (f.ex not authorized)
|
|
94
|
-
if (err != null) return handleCallback(callback, err, null);
|
|
95
|
-
// Check if the user exists and update i
|
|
96
|
-
const findOptions = Object.assign({ projection: { dbName: 1 } }, finalOptions);
|
|
97
|
-
collection.find({ user: username }, findOptions).toArray(err => {
|
|
98
|
-
// We got an error (f.ex not authorized)
|
|
99
|
-
if (err != null) return handleCallback(callback, err, null);
|
|
100
|
-
// Add command keys
|
|
101
|
-
finalOptions.upsert = true;
|
|
102
|
-
|
|
103
|
-
// We have a user, let's update the password or upsert if not
|
|
104
|
-
updateOne(
|
|
105
|
-
collection,
|
|
106
|
-
{ user: username },
|
|
107
|
-
{ $set: { user: username, pwd: userPassword } },
|
|
108
|
-
finalOptions,
|
|
109
|
-
err => {
|
|
110
|
-
if (count === 0 && err)
|
|
111
|
-
return handleCallback(callback, null, [{ user: username, pwd: userPassword }]);
|
|
112
|
-
if (err) return handleCallback(callback, err, null);
|
|
113
|
-
handleCallback(callback, null, [{ user: username, pwd: userPassword }]);
|
|
114
|
-
}
|
|
115
|
-
);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (err) return handleCallback(callback, err);
|
|
123
|
-
handleCallback(callback, err, r);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Fetch all collections for the current db.
|
|
129
|
-
*
|
|
130
|
-
* @method
|
|
131
|
-
* @param {Db} db The Db instance on which to fetch collections.
|
|
132
|
-
* @param {object} [options] Optional settings. See Db.prototype.collections for a list of options.
|
|
133
|
-
* @param {Db~collectionsResultCallback} [callback] The results callback
|
|
134
|
-
*/
|
|
135
|
-
function collections(db, options, callback) {
|
|
136
|
-
let Collection = loadCollection();
|
|
137
|
-
|
|
138
|
-
options = Object.assign({}, options, { nameOnly: true });
|
|
139
|
-
// Let's get the collection names
|
|
140
|
-
db.listCollections({}, options).toArray((err, documents) => {
|
|
141
|
-
if (err != null) return handleCallback(callback, err, null);
|
|
142
|
-
// Filter collections removing any illegal ones
|
|
143
|
-
documents = documents.filter(doc => {
|
|
144
|
-
return doc.name.indexOf('$') === -1;
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
// Return the collection objects
|
|
148
|
-
handleCallback(
|
|
149
|
-
callback,
|
|
150
|
-
null,
|
|
151
|
-
documents.map(d => {
|
|
152
|
-
return new Collection(
|
|
153
|
-
db,
|
|
154
|
-
db.s.topology,
|
|
155
|
-
db.databaseName,
|
|
156
|
-
d.name,
|
|
157
|
-
db.s.pkFactory,
|
|
158
|
-
db.s.options
|
|
159
|
-
);
|
|
160
|
-
})
|
|
161
|
-
);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
37
|
/**
|
|
166
38
|
* Creates an index on the db and collection.
|
|
167
39
|
* @method
|
|
@@ -248,50 +120,6 @@ function createListener(db, e, object) {
|
|
|
248
120
|
return listener;
|
|
249
121
|
}
|
|
250
122
|
|
|
251
|
-
/**
|
|
252
|
-
* Drop a collection from the database, removing it permanently. New accesses will create a new collection.
|
|
253
|
-
*
|
|
254
|
-
* @method
|
|
255
|
-
* @param {Db} db The Db instance on which to drop the collection.
|
|
256
|
-
* @param {string} name Name of collection to drop
|
|
257
|
-
* @param {Object} [options] Optional settings. See Db.prototype.dropCollection for a list of options.
|
|
258
|
-
* @param {Db~resultCallback} [callback] The results callback
|
|
259
|
-
*/
|
|
260
|
-
function dropCollection(db, name, options, callback) {
|
|
261
|
-
executeCommand(db, name, options, (err, result) => {
|
|
262
|
-
// Did the user destroy the topology
|
|
263
|
-
if (db.serverConfig && db.serverConfig.isDestroyed()) {
|
|
264
|
-
return callback(new MongoError('topology was destroyed'));
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (err) return handleCallback(callback, err);
|
|
268
|
-
if (result.ok) return handleCallback(callback, null, true);
|
|
269
|
-
handleCallback(callback, null, false);
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Drop a database, removing it permanently from the server.
|
|
275
|
-
*
|
|
276
|
-
* @method
|
|
277
|
-
* @param {Db} db The Db instance to drop.
|
|
278
|
-
* @param {Object} cmd The command document.
|
|
279
|
-
* @param {Object} [options] Optional settings. See Db.prototype.dropDatabase for a list of options.
|
|
280
|
-
* @param {Db~resultCallback} [callback] The results callback
|
|
281
|
-
*/
|
|
282
|
-
function dropDatabase(db, cmd, options, callback) {
|
|
283
|
-
executeCommand(db, cmd, options, (err, result) => {
|
|
284
|
-
// Did the user destroy the topology
|
|
285
|
-
if (db.serverConfig && db.serverConfig.isDestroyed()) {
|
|
286
|
-
return callback(new MongoError('topology was destroyed'));
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (callback == null) return;
|
|
290
|
-
if (err) return handleCallback(callback, err, null);
|
|
291
|
-
handleCallback(callback, null, result.ok ? true : false);
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
|
|
295
123
|
/**
|
|
296
124
|
* Ensures that an index exists. If it does not, creates it.
|
|
297
125
|
*
|
|
@@ -503,44 +331,6 @@ function profilingInfo(db, options, callback) {
|
|
|
503
331
|
}
|
|
504
332
|
}
|
|
505
333
|
|
|
506
|
-
/**
|
|
507
|
-
* Remove a user from a database
|
|
508
|
-
*
|
|
509
|
-
* @method
|
|
510
|
-
* @param {Db} db The Db instance on which to remove the user.
|
|
511
|
-
* @param {string} username The username.
|
|
512
|
-
* @param {object} [options] Optional settings. See Db.prototype.removeUser for a list of options.
|
|
513
|
-
* @param {Db~resultCallback} [callback] The command result callback
|
|
514
|
-
*/
|
|
515
|
-
function removeUser(db, username, options, callback) {
|
|
516
|
-
let Db = loadDb();
|
|
517
|
-
|
|
518
|
-
// Attempt to execute command
|
|
519
|
-
executeAuthRemoveUserCommand(db, username, options, (err, result) => {
|
|
520
|
-
if (err && err.code === -5000) {
|
|
521
|
-
const finalOptions = applyWriteConcern(Object.assign({}, options), { db }, options);
|
|
522
|
-
// If we have another db set
|
|
523
|
-
const db = options.dbName ? new Db(options.dbName, db.s.topology, db.s.options) : db;
|
|
524
|
-
|
|
525
|
-
// Fetch a user collection
|
|
526
|
-
const collection = db.collection(CONSTANTS.SYSTEM_USER_COLLECTION);
|
|
527
|
-
|
|
528
|
-
// Locate the user
|
|
529
|
-
findOne(collection, { user: username }, finalOptions, (err, user) => {
|
|
530
|
-
if (user == null) return handleCallback(callback, err, false);
|
|
531
|
-
remove(collection, { user: username }, finalOptions, err => {
|
|
532
|
-
handleCallback(callback, err, true);
|
|
533
|
-
});
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
if (err) return handleCallback(callback, err);
|
|
540
|
-
handleCallback(callback, err, result);
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
|
|
544
334
|
// Validate the database name
|
|
545
335
|
function validateDatabaseName(databaseName) {
|
|
546
336
|
if (typeof databaseName !== 'string')
|
|
@@ -665,165 +455,14 @@ function createIndexUsingCreateIndexes(db, name, fieldOrSpec, options, callback)
|
|
|
665
455
|
});
|
|
666
456
|
}
|
|
667
457
|
|
|
668
|
-
/**
|
|
669
|
-
* Run the createUser command.
|
|
670
|
-
*
|
|
671
|
-
* @param {Db} db The Db instance on which to execute the command.
|
|
672
|
-
* @param {string} username The username of the user to add.
|
|
673
|
-
* @param {string} password The password of the user to add.
|
|
674
|
-
* @param {object} [options] Optional settings. See Db.prototype.addUser for a list of options.
|
|
675
|
-
* @param {Db~resultCallback} [callback] The command result callback
|
|
676
|
-
*/
|
|
677
|
-
function executeAuthCreateUserCommand(db, username, password, options, callback) {
|
|
678
|
-
// Special case where there is no password ($external users)
|
|
679
|
-
if (typeof username === 'string' && password != null && typeof password === 'object') {
|
|
680
|
-
options = password;
|
|
681
|
-
password = null;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
// Unpack all options
|
|
685
|
-
if (typeof options === 'function') {
|
|
686
|
-
callback = options;
|
|
687
|
-
options = {};
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
// Error out if we digestPassword set
|
|
691
|
-
if (options.digestPassword != null) {
|
|
692
|
-
return callback(
|
|
693
|
-
toError(
|
|
694
|
-
"The digestPassword option is not supported via add_user. Please use db.command('createUser', ...) instead for this option."
|
|
695
|
-
)
|
|
696
|
-
);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
// Get additional values
|
|
700
|
-
const customData = options.customData != null ? options.customData : {};
|
|
701
|
-
let roles = Array.isArray(options.roles) ? options.roles : [];
|
|
702
|
-
const maxTimeMS = typeof options.maxTimeMS === 'number' ? options.maxTimeMS : null;
|
|
703
|
-
|
|
704
|
-
// If not roles defined print deprecated message
|
|
705
|
-
if (roles.length === 0) {
|
|
706
|
-
console.log('Creating a user without roles is deprecated in MongoDB >= 2.6');
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
// Get the error options
|
|
710
|
-
const commandOptions = { writeCommand: true };
|
|
711
|
-
if (options['dbName']) commandOptions.dbName = options['dbName'];
|
|
712
|
-
|
|
713
|
-
// Add maxTimeMS to options if set
|
|
714
|
-
if (maxTimeMS != null) commandOptions.maxTimeMS = maxTimeMS;
|
|
715
|
-
|
|
716
|
-
// Check the db name and add roles if needed
|
|
717
|
-
if (
|
|
718
|
-
(db.databaseName.toLowerCase() === 'admin' || options.dbName === 'admin') &&
|
|
719
|
-
!Array.isArray(options.roles)
|
|
720
|
-
) {
|
|
721
|
-
roles = ['root'];
|
|
722
|
-
} else if (!Array.isArray(options.roles)) {
|
|
723
|
-
roles = ['dbOwner'];
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
const digestPassword = db.s.topology.lastIsMaster().maxWireVersion >= 7;
|
|
727
|
-
|
|
728
|
-
// Build the command to execute
|
|
729
|
-
let command = {
|
|
730
|
-
createUser: username,
|
|
731
|
-
customData: customData,
|
|
732
|
-
roles: roles,
|
|
733
|
-
digestPassword
|
|
734
|
-
};
|
|
735
|
-
|
|
736
|
-
// Apply write concern to command
|
|
737
|
-
command = applyWriteConcern(command, { db }, options);
|
|
738
|
-
|
|
739
|
-
let userPassword = password;
|
|
740
|
-
|
|
741
|
-
if (!digestPassword) {
|
|
742
|
-
// Use node md5 generator
|
|
743
|
-
const md5 = crypto.createHash('md5');
|
|
744
|
-
// Generate keys used for authentication
|
|
745
|
-
md5.update(username + ':mongo:' + password);
|
|
746
|
-
userPassword = md5.digest('hex');
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
// No password
|
|
750
|
-
if (typeof password === 'string') {
|
|
751
|
-
command.pwd = userPassword;
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
// Force write using primary
|
|
755
|
-
commandOptions.readPreference = ReadPreference.primary;
|
|
756
|
-
|
|
757
|
-
// Execute the command
|
|
758
|
-
executeCommand(db, command, commandOptions, (err, result) => {
|
|
759
|
-
if (err && err.ok === 0 && err.code === undefined)
|
|
760
|
-
return handleCallback(callback, { code: -5000 }, null);
|
|
761
|
-
if (err) return handleCallback(callback, err, null);
|
|
762
|
-
handleCallback(
|
|
763
|
-
callback,
|
|
764
|
-
!result.ok ? toError(result) : null,
|
|
765
|
-
result.ok ? [{ user: username, pwd: '' }] : null
|
|
766
|
-
);
|
|
767
|
-
});
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
* Run the dropUser command.
|
|
772
|
-
*
|
|
773
|
-
* @param {Db} db The Db instance on which to execute the command.
|
|
774
|
-
* @param {string} username The username of the user to remove.
|
|
775
|
-
* @param {object} [options] Optional settings. See Db.prototype.removeUser for a list of options.
|
|
776
|
-
* @param {Db~resultCallback} [callback] The command result callback
|
|
777
|
-
*/
|
|
778
|
-
function executeAuthRemoveUserCommand(db, username, options, callback) {
|
|
779
|
-
if (typeof options === 'function') (callback = options), (options = {});
|
|
780
|
-
options = options || {};
|
|
781
|
-
|
|
782
|
-
// Did the user destroy the topology
|
|
783
|
-
if (db.serverConfig && db.serverConfig.isDestroyed())
|
|
784
|
-
return callback(new MongoError('topology was destroyed'));
|
|
785
|
-
// Get the error options
|
|
786
|
-
const commandOptions = { writeCommand: true };
|
|
787
|
-
if (options['dbName']) commandOptions.dbName = options['dbName'];
|
|
788
|
-
|
|
789
|
-
// Get additional values
|
|
790
|
-
const maxTimeMS = typeof options.maxTimeMS === 'number' ? options.maxTimeMS : null;
|
|
791
|
-
|
|
792
|
-
// Add maxTimeMS to options if set
|
|
793
|
-
if (maxTimeMS != null) commandOptions.maxTimeMS = maxTimeMS;
|
|
794
|
-
|
|
795
|
-
// Build the command to execute
|
|
796
|
-
let command = {
|
|
797
|
-
dropUser: username
|
|
798
|
-
};
|
|
799
|
-
|
|
800
|
-
// Apply write concern to command
|
|
801
|
-
command = applyWriteConcern(command, { db }, options);
|
|
802
|
-
|
|
803
|
-
// Force write using primary
|
|
804
|
-
commandOptions.readPreference = ReadPreference.primary;
|
|
805
|
-
|
|
806
|
-
// Execute the command
|
|
807
|
-
executeCommand(db, command, commandOptions, (err, result) => {
|
|
808
|
-
if (err && !err.ok && err.code === undefined) return handleCallback(callback, { code: -5000 });
|
|
809
|
-
if (err) return handleCallback(callback, err, null);
|
|
810
|
-
handleCallback(callback, null, result.ok ? true : false);
|
|
811
|
-
});
|
|
812
|
-
}
|
|
813
|
-
|
|
814
458
|
module.exports = {
|
|
815
|
-
addUser,
|
|
816
|
-
collections,
|
|
817
459
|
createListener,
|
|
818
460
|
createIndex,
|
|
819
|
-
dropCollection,
|
|
820
|
-
dropDatabase,
|
|
821
461
|
ensureIndex,
|
|
822
462
|
evaluate,
|
|
823
463
|
executeCommand,
|
|
824
464
|
executeDbAdminCommand,
|
|
825
465
|
indexInformation,
|
|
826
466
|
profilingInfo,
|
|
827
|
-
removeUser,
|
|
828
467
|
validateDatabaseName
|
|
829
468
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongodb",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.7",
|
|
4
4
|
"description": "The official MongoDB driver for Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"kerberos": "^1.1.0",
|
|
21
21
|
"mongodb-client-encryption": "^1.0.0",
|
|
22
22
|
"mongodb-extjson": "^2.1.2",
|
|
23
|
-
"snappy": "^6.
|
|
23
|
+
"snappy": "^6.3.4",
|
|
24
24
|
"bson-ext": "^2.0.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"semver": "^5.5.0",
|
|
50
50
|
"sinon": "^4.3.0",
|
|
51
51
|
"sinon-chai": "^3.2.0",
|
|
52
|
-
"snappy": "^6.
|
|
52
|
+
"snappy": "^6.3.4",
|
|
53
53
|
"standard-version": "^4.4.0",
|
|
54
54
|
"util.promisify": "^1.0.1",
|
|
55
55
|
"worker-farm": "^1.5.0",
|