Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

544
Views
MongoError: bad auth : Authentication failed

I am trying to make a roblox mongodb connector, but the connection is not working properly. It says MongoError: bad auth : Authentication failed. whenever I try.

Here is my code

const express = require('express')
const app = require('express')()
const bodyParser = require('body-parser');
const mongoose = require("mongoose")

const username = process.env.USERNAME
const passwordAuth = process.env.PASSWORD

const mongoPass = process.env.MONGO_PASS
const mongoUser = process.env.MONGO_USER

mongoose.connect(`mongodb+srv://${mongoUser}:${mongoPass}@cluster0.i3et1.gcp.mongodb.net/testing?retryWrites=true&w=majority`, {useNewUrlParser: true, useUnifiedTopology: true });

var db = mongoose.connection;

db.on("error", console.error.bind(console, "connection error:"));

db.once("open", function() {
    console.log("Connection To MongoDB Atlas Successful!");
});

app.use(express.json());
app.use((req, res, next) => {  
    const auth = {login: username, password: passwordAuth}

    // parse login and password from headers
    const b64auth = (req.headers.authorization || '').split(' ')[1] || ''
    const [login, password] = Buffer.from(b64auth, 'base64').toString().split(':')

    // Verify login and password are set and correct
    if (login && password && login === auth.login && password === auth.password) {
        // Access granted...
        return next()
    }

    res.set('WWW-Authenticate', 'Basic realm="401"')
    res.status(401).send('Authentication required.')
})

I have checked the mongo_user and the mongo_pass many times, and they are exactly identical to my user and pass.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!