MongoDB authentication failed

AJA J5/11/2023
I am trying to connect to my MongoDB hosted on Railway. I just created the MongoDB, so it only contains a 'test' db with no collection.

When I do not append the URL with db name, I can use mongosh to connect and set to 'test' DB.

But when I do append the db name, , 'MONGO_URL/test', I get:
[DEBUG-ConnectionPool:12243] 1683846894064 connection attempt failed with error [{"ok":0,"code":18,"codeName":"AuthenticationFailed"}] {
type: 'debug',
message: 'connection attempt failed with error [{"ok":0,"code":18,"codeName":"AuthenticationFailed"}]',
className: 'ConnectionPool',
pid: 12243,
date: 1683846894064
}

I am new to this, any help is greatly appreciated!
AJA J5/11/2023
a686cf21-bbfd-4ddb-9e0c-5c11cd434e88
Bbrody5/12/2023
can I see a screenshot of your service variables
AJA J5/12/2023
AJA J5/12/2023
${{MongoDB.MONGO_URL}}
Bbrody5/12/2023
can you connect to it with an external tool like mongodb compass
AJA J5/12/2023
Haven't tried mongodb compass. Let me download that
mongosh and PyMongo returned the same thing...
Tried compass. Same result
I can connect using the URL, without adding the db name.
After I add the db name, I get authentication error
Bbrody5/12/2023
would the same thing happen with a brand new database?
AJA J5/12/2023
yes, I tried launching a new MongoDB, same result
Bbrody5/12/2023
okay i will look into it
Bbrody5/12/2023
i can connect just fine, simply dont add the db name to the url
AJA J5/12/2023
I can also connect without adding the db name to the url......
Guess I need to proceed this way for now
Bbrody5/12/2023
if it works it works, no need to complicate things, perhaps the version of mongodb they run does not support defining the database in the url
Bbrody5/12/2023
the MONGO_URL does not have a database defined in it, and now we know why
AJA J5/12/2023
I see. Another question if I may
Bbrody5/12/2023
ofc
AJA J5/12/2023
when I am testing locally, the React app and server run on HTTP, but the MongoDB URL is on HTTPS, causing CORS issue... How can I get around this
Bbrody5/12/2023
isnt cors a browser thing?
Bbrody5/12/2023
youre accessing the mongo database directly from the frontend?
AJA J5/12/2023
Oh you are right. It is not the database call. It is some other POST that caused CORS
Bbrody5/12/2023
okay where are these POST requests going to
AJA J5/12/2023
I have a register post
AJA J5/12/2023
The frontend code is like this

const SERVER_URL = process.env.REACT_APP_SERVER_URL;

function Register() {
const [id, setId] = useState('');
const [passcode, setPasscode] = useState('');

const handleSubmit = async (e) => {
e.preventDefault();

try {
await axios.post(${SERVER_URL}/register, { id, passcode });
alert('Registered successfully');
} catch (error) {
alert('Registration failed');
}
};
AJA J5/12/2023
I am using Flask on the server side and I have

app = Flask(name)
CORS(app)
Bbrody5/12/2023
that says failed with error 500, so even though you get a cors error the bigger issue is the error 500.
but with that said, that isnt a railway problem, so you will have to do some debugging yourself
AJA J5/12/2023
Got it. Thanks for pointing me in the right direction
AJA J5/12/2023
Really appreciate!
Bbrody5/12/2023
no problem!
Bbrody5/12/2023
i wish you luck