cxx
cxx2y ago

Error connecting to MongoDB Atlas

Hello, I'm trying to connect to MongoDB Atlas via mongoose (npm:mongoose) but encountered the following error:
error: Uncaught MongoAPIError: Server record does not share hostname with parent URI
at resolveSRVRecord (file:///home/farish/.cache/deno/npm/registry.npmjs.org/mongodb/4.14.0/lib/connection_string.js:63:19)
at async file:///home/farish/.cache/deno/npm/registry.npmjs.org/mongodb/4.14.0/lib/mongo_client.js:123:31
error: Uncaught MongoAPIError: Server record does not share hostname with parent URI
at resolveSRVRecord (file:///home/farish/.cache/deno/npm/registry.npmjs.org/mongodb/4.14.0/lib/connection_string.js:63:19)
at async file:///home/farish/.cache/deno/npm/registry.npmjs.org/mongodb/4.14.0/lib/mongo_client.js:123:31
My code:
import mongoose from 'npm:mongoose';

await mongoose.connect(
'mongodb+srv://user:pass@main.pj9zc0r.mongodb.net/?retryWrites=true&w=majority',
);
import mongoose from 'npm:mongoose';

await mongoose.connect(
'mongodb+srv://user:pass@main.pj9zc0r.mongodb.net/?retryWrites=true&w=majority',
);
5 Replies
cxx
cxx2y ago
I've added 0.0.0.0/0 to my network access
cxx
cxx2y ago
Solved it
outofcontext
outofcontext10mo ago
hey @cxx , what is the error did you ever face the error connection timed out when trying to connect with the mongodb
cxx
cxx10mo ago
hey sorry i forgot to post the the way i solved this and honestly i forgot how i did it but if im correct, it have to do with deno resolving dns and adding a . to the string so in order to fix the error rewrite a mongodb dns resolver and check if the resolved dns have a . and remove if it does to be honest im shocked that someone is still facing the same problem with me after several months if you have any more problems, id be happy to help
outofcontext
outofcontext10mo ago
I haven't faced the same issue but it is similar to this issue, when I try to connect with the mongodb then it always shows the error: connection timed out.. but it is working correctly in node. Yeah!! once I will try this and thank you for responding