Getting error on mongoDB connection

Am getting error when connecting to mongoDB hosted on railway.app when using the connection uri without database name i.e. mongodb://user:[email protected]:24727 it works fine and connects but on using uri with db name mongodb://user:[email protected]:24727/dbname gives authentication error MongoServerError: Authentication failed. at Connection.onMessage (/app/node_modules/mongodb/lib/cmap/connection.js:205:26) at MessageStream.<anonymous> (/app/node_modules/mongodb/lib/cmap/connection.js:64:60) at MessageStream.emit (node:events:517:28) at processIncomingData (/app/node_modules/mongodb/lib/cmap/message_stream.js:117:16) at MessageStream._write (/app/node_modules/mongodb/lib/cmap/message_stream.js:33:9) at writeOrBuffer (node:internal/streams/writable:392:12) at _write (node:internal/streams/writable:333:10) at Writable.write (node:internal/streams/writable:337:10) at Socket.ondata (node:internal/streams/readable:777:22) at Socket.emit (node:events:517:28) { ok: 0, code: 18, codeName: 'AuthenticationFailed', connectionGeneration: 1, [Symbol(errorLabels)]: Set(2) { 'HandshakeError', 'ResetPool' } }
Solution:
specify the dbName
No description
Jump to solution
12 Replies
Percy
Percy9mo ago
Project ID: 47c310df-3a23-400f-aa2d-abb66fa666cc
KothariG
KothariGOP9mo ago
47c310df-3a23-400f-aa2d-abb66fa666cc works fine without using database name in the url but gives authentication error when including database name have already checked connection and database name, collections ets in mongodb compass
Brody
Brody9mo ago
if it's anything like mongose you need to specify the desired database via some config object
KothariG
KothariGOP9mo ago
could you please give a reference or example because wherever i search even when connecting mongodb atlas database name is included in in connection string @Brody
Brody
Brody9mo ago
please link me to the npm page for the mongodb client you are using in code and I will look through it's documentation for you
KothariG
KothariGOP9mo ago
@Brody i am using mongoose. I am surprised cause i am connecting fine with mongodb atlas with the given format <connectionuri>/<dbname>
KothariG
KothariGOP9mo ago
npm
mongoose
Mongoose MongoDB ODM. Latest version: 8.1.3, last published: 2 days ago. Start using mongoose in your project by running npm i mongoose. There are 15180 other projects in the npm registry using mongoose.
Brody
Brody9mo ago
atlas does not run the same type of mongo database as railway oh that is mongose
KothariG
KothariGOP9mo ago
any solutions?
Solution
Brody
Brody9mo ago
specify the dbName
No description
KothariG
KothariGOP9mo ago
thanks a lot @Brody .Really
Brody
Brody9mo ago
no problem!
Want results from more Discord servers?
Add your server