I have problems with the database when I do a deploy.
I have a mongo DB database that is connected to a node js, to connect to mongo I use the url that mongo gives me:
mongodb://mongo:[my-data]@containers-us-west-184.railway.app:5712
the thing is that it creates a database called "test" and not "my data".
already used this form: mongodb://mongo:[my-data]@containers-us-west-184.railway.app:5712/my_db
but it does not work for me
I get this error:
MongoServerError: Authentication failed.
at Connection.onMessage (/app/node_modules/mongodb/lib/cmap/connection.js:202:26)
at MessageStream.<anonymous> (/app/node_modules/mongodb/lib/cmap/connection.js:61:60)
at MessageStream.emit (node:events:513:28)
at processIncomingData (/app/node_modules/mongodb/lib/cmap/message_stream.js:124:16)
at MessageStream._write (/app/node_modules/mongodb/lib/cmap/message_stream.js:33:9)
at writeOrBuffer (node:internal/streams/writable:391:12)
at _write (node:internal/streams/writable:332:10)
at MessageStream.Writable.write (node:internal/streams/writable:336:10)
at Socket.ondata (node:internal/streams/readable:754:22)
at Socket.emit (node:events:513:28) {
ok: 0,
code: 18,
codeName: 'AuthenticationFailed',
connectionGeneration: 0,
[Symbol(errorLabels)]: Set(2) { 'HandshakeError', 'ResetPool' }
}
npm WARN config production Use
--omit=dev
instead.21 Replies
Project ID:
N/A
Please don’t open more than one help thread
Are you using the MONGO_URL reference variable for connecting to your database?
yes i am
Have you changed your reference from “my data” to “test” to see if it will connect and work for you?
Or manually create the database of “my data” or whatever you are trying to call it by clicking the “new database” button?
I already did that in the capture but it doesn't connect me anyway
Hmmm
I'm taking MONGO_URL to connect but it doesn't work
Can you show me your environment variables in your service (app)
In DB_CONECTION there is this url: mongodb://mongo:[my-data]@containers-us-west-184.railway.app:5712
It would be better to use reference variables, simply because if you roll your credentials, they will automatically update for you in your service…
But that’s not the issue here
let me explain, I used this link
mongodb://mongo:[my-data]@containers-us-west-184.railway.app:5712/my_db
when I did this I got the error because with the "/my_db" it would automatically create the database.
using this link without the "/my_db" does work but it does not change the database name, it uses the default "test".
I don’t usually work with Mongo, so, I’m trying to understand everything… without specifying a database name, it will connect to “test” by default, yes. As long as you are calling to the database by the correct name it should work. Are you able to share your repo?
are you using mongoose?
There’s the guy!
ive seen this issue before a few times
yes i using mongoose
oh and what is the solution?
specify the database name with that options parameter
https://mongoosejs.com/docs/api/mongoose.html#Mongoose.prototype.connect()
but please also use reference variables like vin has said
https://docs.railway.app/develop/variables#reference-variables
once you have setup a
MONGO_URL
reference variable please show another screenshot of your service variablesok perfect I'll do it