isAtlas.js 600 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. const getConstructorName = require('../getConstructorName');
  3. module.exports = function isAtlas(topologyDescription) {
  4. if (getConstructorName(topologyDescription) !== 'TopologyDescription') {
  5. return false;
  6. }
  7. const hostnames = Array.from(topologyDescription.servers.keys());
  8. if (hostnames.length === 0) {
  9. return false;
  10. }
  11. for (let i = 0, il = hostnames.length; i < il; ++i) {
  12. const url = new URL(hostnames[i]);
  13. if (
  14. url.hostname.endsWith('.mongodb.net') === false ||
  15. url.port !== '27017'
  16. ) {
  17. return false;
  18. }
  19. }
  20. return true;
  21. };