Skip to content

Commit

Permalink
Merge pull request #12110 from skrtheboss/fix/is-atlas-check
Browse files Browse the repository at this point in the history
fix: isAtlas check not working properly
  • Loading branch information
vkarpov15 committed Jul 16, 2022
2 parents 1445c20 + 37b10af commit f95373d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/helpers/topology/isAtlas.js
Expand Up @@ -2,25 +2,30 @@

const getConstructorName = require('../getConstructorName');

/**
* @typedef { import('mongodb').TopologyDescription } TopologyDescription
*/

/**
* Checks if topologyDescription contains servers connected to an atlas instance
*
* @param {TopologyDescription} topologyDescription
* @returns {boolean}
*/
module.exports = function isAtlas(topologyDescription) {
if (getConstructorName(topologyDescription) !== 'TopologyDescription') {
return false;
}

const hostnames = Array.from(topologyDescription.servers.keys());

if (hostnames.length === 0) {
if (topologyDescription.servers.size === 0) {
return false;
}

for (let i = 0, il = hostnames.length; i < il; ++i) {
const url = new URL(hostnames[i]);
if (
url.hostname.endsWith('.mongodb.net') === false ||
url.port !== '27017'
) {
for (const server of topologyDescription.servers.values()) {
if (server.host.endsWith('.mongodb.net') === false || server.port !== 27017) {
return false;
}
}

return true;
};

0 comments on commit f95373d

Please sign in to comment.