Skip to content

Commit 542859d

Browse files
committed
feat(mongo-client): remove deprecated logout and print warning
Logging out on a connected MongoClient has been disallowed since the v3.0.0 major release due to incompatibilities with v3.6+ of the server. A warning is now printed alerting users who might still erroneously be using this feature.
1 parent d4d11d8 commit 542859d

File tree

3 files changed

+5
-40
lines changed

3 files changed

+5
-40
lines changed

lib/mongo_client.js

+4-19
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const executeOperation = require('./utils').executeOperation;
77
const handleCallback = require('./utils').handleCallback;
88
const inherits = require('util').inherits;
99
const MongoError = require('mongodb-core').MongoError;
10+
const deprecate = require('util').deprecate;
1011

1112
// Operations
1213
const connectOp = require('./operations/mongo_client_ops').connectOp;
13-
const logout = require('./operations/mongo_client_ops').logout;
1414
const validOptions = require('./operations/mongo_client_ops').validOptions;
1515

1616
/**
@@ -170,25 +170,10 @@ MongoClient.prototype.connect = function(callback) {
170170
});
171171
};
172172

173-
/**
174-
* Logout user from server, fire off on all connections and remove all auth info
175-
* @method
176-
* @param {object} [options] Optional settings.
177-
* @param {string} [options.dbName] Logout against different database than current.
178-
* @param {Db~resultCallback} [callback] The command result callback
179-
* @return {Promise} returns Promise if no callback passed
180-
*/
181-
MongoClient.prototype.logout = function(options, callback) {
173+
MongoClient.prototype.logout = deprecate(function(options, callback) {
182174
if (typeof options === 'function') (callback = options), (options = {});
183-
options = options || {};
184-
185-
// Establish the correct database name
186-
const dbName = this.s.options.authSource ? this.s.options.authSource : this.s.options.dbName;
187-
188-
return executeOperation(this, logout, [this, dbName, callback], {
189-
skipSessions: true
190-
});
191-
};
175+
callback(null, true);
176+
}, 'Multiple authentication is prohibited on a connected client, please only authenticate once per MongoClient');
192177

193178
/**
194179
* Close the db and its underlying connections

lib/operations/mongo_client_ops.js

+1-16
Original file line numberDiff line numberDiff line change
@@ -521,21 +521,6 @@ function legacyTransformUrlOptions(object) {
521521
return mergeOptions(createUnifiedOptions({}, object), object, false);
522522
}
523523

524-
/**
525-
* Logout user from server, fire off on all connections and remove all auth info.
526-
*
527-
* @method
528-
* @param {MongoClient} mongoClient The MongoClient instance on which to logout.
529-
* @param {object} [options] Optional settings. See MongoClient.prototype.logout for a list of options.
530-
* @param {Db~resultCallback} [callback] The command result callback
531-
*/
532-
function logout(mongoClient, dbName, callback) {
533-
mongoClient.topology.logout(dbName, err => {
534-
if (err) return callback(err);
535-
callback(null, true);
536-
});
537-
}
538-
539524
function mergeOptions(target, source, flatten) {
540525
for (const name in source) {
541526
if (source[name] && typeof source[name] === 'object' && flatten) {
@@ -688,4 +673,4 @@ function validOptions(options) {
688673
}
689674
}
690675

691-
module.exports = { connectOp, logout, validOptions };
676+
module.exports = { connectOp, validOptions };

lib/topologies/topology_base.js

-5
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,6 @@ class TopologyBase extends EventEmitter {
375375
this.s.coreTopology.auth.apply(this.s.coreTopology, args);
376376
}
377377

378-
logout() {
379-
var args = Array.prototype.slice.call(arguments, 0);
380-
this.s.coreTopology.logout.apply(this.s.coreTopology, args);
381-
}
382-
383378
/**
384379
* All raw connections
385380
* @method

0 commit comments

Comments
 (0)