I am working on connecting to a MongoDB Atlas database but continue to get this error:
MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"
I've tried hardcoding the username and password for ATLAS_URI in my .env file, as well as placing the environment variables within ATLAS_URI but continue to get the same error. Here is my .env file:
ATLAS_URI = mongodb+srv://{DBUSER}:{DBPWD}@qac.mqn4ubr.mongodb.net/?retryWrites=true&w=majority
and this is what I have stored in conn.mjs & loadEnvironment.mjs:
import { MongoClient } from 'mongodb'
const connectionString = process.env.ATLAS_URI || ''
console.log(connectionString)
const client = new MongoClient(connectionString)
let conn
try {
conn = await client.connect()
} catch(err) {
console.log(err)
}
let db = conn.db('sample_training')
export default db
js
import dotenv from 'dotenv'
dotenv.config()
I've been following this tutorial:MERN tutorial: MongoDB,
as well as this solution:MongoParseError: Invalid scheme but nothing has fixed this.
The expectation is for the server to run on given port