diff --git a/lib/mongo_client.js b/lib/mongo_client.js index 16be251bc43..a384bd9e68f 100644 --- a/lib/mongo_client.js +++ b/lib/mongo_client.js @@ -67,6 +67,7 @@ const closeOperation = require('./operations/mongo_client_ops').closeOperation; * @property {string} [kmsProviders.local.key] The master key used to encrypt/decrypt data keys * @property {object} [schemaMap] A map of namespaces to a local JSON schema for encryption * @property {boolean} [bypassAutoEncryption] Allows the user to bypass auto encryption, maintaining implicit decryption + * @param {string} [extraOptions.mongocryptURI] A local process the driver communicates with to determine how to encrypt values in a command. Defaults to "mongodb://%2Fvar%2Fmongocryptd.sock" if domain sockets are available or "mongodb://localhost:27020" otherwise. */ /** diff --git a/lib/operations/mongo_client_ops.js b/lib/operations/mongo_client_ops.js index e0b8dd53330..bce2e3dc052 100644 --- a/lib/operations/mongo_client_ops.js +++ b/lib/operations/mongo_client_ops.js @@ -439,10 +439,14 @@ function createTopology(mongoClient, topologyType, options, callback) { } const MongoClient = loadClient(); - const connectionString = - os.platform() === 'win32' - ? 'mongodb://localhost:27020/?serverSelectionTimeoutMS=1000' - : 'mongodb://%2Ftmp%2Fmongocryptd.sock/?serverSelectionTimeoutMS=1000'; + let connectionString; + if (options.autoEncryption.extraOptions && options.autoEncryption.extraOptions.mongocryptURI) { + connectionString = options.autoEncryption.extraOptions.mongocryptURI; + } else if (os.platform() === 'win32') { + connectionString = 'mongodb://localhost:27020/?serverSelectionTimeoutMS=1000'; + } else { + connectionString = 'mongodb://%2Ftmp%2Fmongocryptd.sock/?serverSelectionTimeoutMS=1000'; + } const mongocryptdClient = new MongoClient(connectionString, { useUnifiedTopology: true }); mongocryptdClient.connect(err => {