Cant connect to mongodb atlas

const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
const mongoURI = "mongodb+srv://Purnendu:<password>";

async function main() {
await mongoose.connect(mongoURI);
console.log("Connected to Mongo");

This gives the error as: -

MongoAPIError: URI must include hostname, domain name, and tld

Please help

Can you connect by shell?
Does your password has any special characters like #,@
If yes change it to a simple one or you have to encode special characters

If the code you shared is the exact code you are using then your URI is wrong because

must be the actual password, not string <password> as you shared.

Unless, of course, if mongoose (which I am a total ignorant) provides magic that maps the string <password> to the actual password provided by some environment variable.

1 Like

@Purnendu_Kumar_Misra, it would be nice to know if your issue is resolved. A followup would show respect to the people that read, analyzed and replied to your thread.

Ad Thanks vance

1 Like