From 542859dd480173918dfdb31ea868bb9779fc1e81 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Fri, 22 Feb 2019 22:37:32 -0500 Subject: [PATCH] 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. --- lib/mongo_client.js | 23 ++++------------------- lib/operations/mongo_client_ops.js | 17 +---------------- lib/topologies/topology_base.js | 5 ----- 3 files changed, 5 insertions(+), 40 deletions(-) diff --git a/lib/mongo_client.js b/lib/mongo_client.js index e6e9381331..4ac240d19c 100644 --- a/lib/mongo_client.js +++ b/lib/mongo_client.js @@ -7,10 +7,10 @@ const executeOperation = require('./utils').executeOperation; const handleCallback = require('./utils').handleCallback; const inherits = require('util').inherits; const MongoError = require('mongodb-core').MongoError; +const deprecate = require('util').deprecate; // Operations const connectOp = require('./operations/mongo_client_ops').connectOp; -const logout = require('./operations/mongo_client_ops').logout; const validOptions = require('./operations/mongo_client_ops').validOptions; /** @@ -170,25 +170,10 @@ MongoClient.prototype.connect = function(callback) { }); }; -/** - * Logout user from server, fire off on all connections and remove all auth info - * @method - * @param {object} [options] Optional settings. - * @param {string} [options.dbName] Logout against different database than current. - * @param {Db~resultCallback} [callback] The command result callback - * @return {Promise} returns Promise if no callback passed - */ -MongoClient.prototype.logout = function(options, callback) { +MongoClient.prototype.logout = deprecate(function(options, callback) { if (typeof options === 'function') (callback = options), (options = {}); - options = options || {}; - - // Establish the correct database name - const dbName = this.s.options.authSource ? this.s.options.authSource : this.s.options.dbName; - - return executeOperation(this, logout, [this, dbName, callback], { - skipSessions: true - }); -}; + callback(null, true); +}, 'Multiple authentication is prohibited on a connected client, please only authenticate once per MongoClient'); /** * Close the db and its underlying connections diff --git a/lib/operations/mongo_client_ops.js b/lib/operations/mongo_client_ops.js index 85bf5a6698..d7dfb492d9 100644 --- a/lib/operations/mongo_client_ops.js +++ b/lib/operations/mongo_client_ops.js @@ -521,21 +521,6 @@ function legacyTransformUrlOptions(object) { return mergeOptions(createUnifiedOptions({}, object), object, false); } -/** - * Logout user from server, fire off on all connections and remove all auth info. - * - * @method - * @param {MongoClient} mongoClient The MongoClient instance on which to logout. - * @param {object} [options] Optional settings. See MongoClient.prototype.logout for a list of options. - * @param {Db~resultCallback} [callback] The command result callback - */ -function logout(mongoClient, dbName, callback) { - mongoClient.topology.logout(dbName, err => { - if (err) return callback(err); - callback(null, true); - }); -} - function mergeOptions(target, source, flatten) { for (const name in source) { if (source[name] && typeof source[name] === 'object' && flatten) { @@ -688,4 +673,4 @@ function validOptions(options) { } } -module.exports = { connectOp, logout, validOptions }; +module.exports = { connectOp, validOptions }; diff --git a/lib/topologies/topology_base.js b/lib/topologies/topology_base.js index 54f848c974..90ef0ea31d 100644 --- a/lib/topologies/topology_base.js +++ b/lib/topologies/topology_base.js @@ -375,11 +375,6 @@ class TopologyBase extends EventEmitter { this.s.coreTopology.auth.apply(this.s.coreTopology, args); } - logout() { - var args = Array.prototype.slice.call(arguments, 0); - this.s.coreTopology.logout.apply(this.s.coreTopology, args); - } - /** * All raw connections * @method