R
Railway17mo ago
aj3163

MongoDB authentication failed

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!
23 Replies
Percy
Percy17mo ago
Project ID: a686cf21-bbfd-4ddb-9e0c-5c11cd434e88
aj3163
aj316317mo ago
a686cf21-bbfd-4ddb-9e0c-5c11cd434e88
Brody
Brody17mo ago
can I see a screenshot of your service variables
aj3163
aj316317mo ago
aj3163
aj316317mo ago
${{MongoDB.MONGO_URL}}
Brody
Brody17mo ago
can you connect to it with an external tool like mongodb compass
aj3163
aj316317mo ago
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
Brody
Brody17mo ago
would the same thing happen with a brand new database?
aj3163
aj316317mo ago
yes, I tried launching a new MongoDB, same result
Brody
Brody17mo ago
okay i will look into it i can connect just fine, simply dont add the db name to the url
aj3163
aj316317mo ago
I can also connect without adding the db name to the url...... Guess I need to proceed this way for now
Brody
Brody17mo ago
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 the MONGO_URL does not have a database defined in it, and now we know why
aj3163
aj316317mo ago
I see. Another question if I may
Brody
Brody17mo ago
ofc
aj3163
aj316317mo ago
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
Want results from more Discord servers?
Add your server