cxx
cxx•2y 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',
);
8 Replies
cxx
cxxOP•2y ago
I've added 0.0.0.0/0 to my network access
cxx
cxxOP•2y ago
Solved it
0x_!nit
0x_!nit•16mo ago
hey @cxx , what is the error did you ever face the error connection timed out when trying to connect with the mongodb
cxx
cxxOP•16mo 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
0x_!nit
0x_!nit•16mo 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
diszrahul
diszrahul•3mo ago
@0x_!nit I have same "error: connection timed out.. but it is working correctly in node.", were you able to solve it?
0x_!nit
0x_!nit•3mo ago
then again later I switched to node I couldn't find any proper solution to it
diszrahul
diszrahul•3mo ago
Ohh no :partydeno: 😄 Thanks @0x!nit

Did you find this page helpful?