-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
Problem Statement/Rationale
There is a DNS resolution issue when connecting to a MongoDB instance hosted on AWS using MongoDB Compass or the Node.js MongoDB Driver. However, the connection works perfectly fine when using mongosh with the exact same connection string.
Here is the detailed context:
- Working Example with mongosh:
mongosh "mongodb://ec2-3-86-155-52.compute-1.amazonaws.com:27018/liquibase" -u username
The connection succeeds without any issues.
- Failed Example with Node.js Driver:
When attempting to connect using Node.js, the following error occurs:
{{_MongoNetworkError: getaddrinfo ENOTFOUND san1
at Socket.<anonymous>(<path>/node_modules/mongodb/src/cmap/connect.ts:395:16)_}}
This error implies that the hostname san1 cannot be resolved, even though the actual hostname ec2-3-86-155-52.compute-1.amazonaws.com is valid and resolves correctly using DNS.
- Failed Example with MongoDB Compass:
Similarly, the connection using MongoDB Compass fails with the same DNS resolution error, despite entering the correct hostname.
Steps to Reproduce
- Use the following connection string in Compass or Node.js:
mongodb://user:pass@ec2-3-86-155-52.compute-1.amazonaws.com:27018/liquibase?authSource=liquibase&authMechanism=SCRAM-SHA-256&tls=false - Attempt to connect.
- The following error occurs: Unknown macro: {MongoNetworkError}
- However, using the same connection string in mongosh, the connection works:
mongosh "mongodb://ec2-3-86-155-52.compute-1.amazonaws.com:27018/liquibase" -u user
Temporary Workaround: A potential workaround is to add an explicit mapping for the hostname san1 in the local routing table (hosts file) of the PC. This involves associating san1 to the valid IP address (3.86.155.52). For example:
3.86.155.52 san1
However, this workaround is undesirable in production environments, as it requires manual hardcoding of DNS entries for every machine, which is error-prone and unscalable.
Expected Results
MongoDB Compass and the Node.js MongoDB Driver should resolve the correct hostname (ec2-3-86-155-52.compute-1.amazonaws.com) similarly to how it works with mongosh, without requiring any additional DNS configuration.
Actual Results
Both MongoDB Compass and the Node.js MongoDB Driver fail with the getaddrinfo ENOTFOUND san1 error, as if the hostname is being "hardcoded" or redirected incorrectly.
Additional Notes
This issue suggests the potential existence of a hardcoding or misconfiguration in the DNS resolution mechanism in MongoDB Compass and the Node.js MongoDB Driver, which does not align with the behavior of mongosh. Further investigation is needed on how DNS is being handled by those clients.