2 / 4
Jun 2024
const express = require('express'); const cors = require('cors'); const mongoose = require('mongoose'); const mongoURI = "mongodb+srv://Purnendu:<password>@cluster0.ftshfof.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"; async function main() { await mongoose.connect(mongoURI); console.log("Connected to Mongo"); } main();

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.

10 days later