Skip to content

Commit

Permalink
feat(mongo-client): remove deprecated logout and print warning
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mbroadst committed Feb 25, 2019
1 parent d4d11d8 commit 542859d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 40 deletions.
23 changes: 4 additions & 19 deletions lib/mongo_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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
Expand Down
17 changes: 1 addition & 16 deletions lib/operations/mongo_client_ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -688,4 +673,4 @@ function validOptions(options) {
}
}

module.exports = { connectOp, logout, validOptions };
module.exports = { connectOp, validOptions };
5 changes: 0 additions & 5 deletions lib/topologies/topology_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 542859d

Please sign in to comment.