Skip to main content
The Deno 2 Release Candidate is here
Learn more

Resolve Mongo DNS

Resolve MongoDB DNS

Usage

Sometimes, when connecting to MongoDB Atlas, you will get the following error:

Uncaught MongoAPIError: Server record does not share hostname with parent URI

This module counters it by resolving it first.

Example

import { resolveMongoDNS } from 'https://deno.land/x/resolve_mongo_dns/mod.ts';
import mongoose from 'npm:mongoose';

const URI = '...'; // Your MongoDB connection URI

// This will fail when using MongoDB Atlas
await mongoose.connect(URI);

// This will work
const newURI = await resolveMongoDNS(URI);
await mongoose.connect(newURI);