Skip to content

Commit f95373d

Browse files
authored
Merge pull request #12110 from skrtheboss/fix/is-atlas-check
fix: isAtlas check not working properly
2 parents 1445c20 + 37b10af commit f95373d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lib/helpers/topology/isAtlas.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@
22

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

5+
/**
6+
* @typedef { import('mongodb').TopologyDescription } TopologyDescription
7+
*/
8+
9+
/**
10+
* Checks if topologyDescription contains servers connected to an atlas instance
11+
*
12+
* @param {TopologyDescription} topologyDescription
13+
* @returns {boolean}
14+
*/
515
module.exports = function isAtlas(topologyDescription) {
616
if (getConstructorName(topologyDescription) !== 'TopologyDescription') {
717
return false;
818
}
919

10-
const hostnames = Array.from(topologyDescription.servers.keys());
11-
12-
if (hostnames.length === 0) {
20+
if (topologyDescription.servers.size === 0) {
1321
return false;
1422
}
1523

16-
for (let i = 0, il = hostnames.length; i < il; ++i) {
17-
const url = new URL(hostnames[i]);
18-
if (
19-
url.hostname.endsWith('.mongodb.net') === false ||
20-
url.port !== '27017'
21-
) {
24+
for (const server of topologyDescription.servers.values()) {
25+
if (server.host.endsWith('.mongodb.net') === false || server.port !== 27017) {
2226
return false;
2327
}
2428
}
29+
2530
return true;
2631
};

0 commit comments

Comments
 (0)