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
Percy
Percy10mo ago
Project ID: N/A
MantisInABox
MantisInABox10mo ago
Please don’t open more than one help thread Are you using the MONGO_URL reference variable for connecting to your database?
Jesus Soto
Jesus Soto10mo ago
yes i am
MantisInABox
MantisInABox10mo ago
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?
MantisInABox
MantisInABox10mo ago
No description
Jesus Soto
Jesus Soto10mo ago
I already did that in the capture but it doesn't connect me anyway
Jesus Soto
Jesus Soto10mo ago
No description
MantisInABox
MantisInABox10mo ago
Hmmm
Jesus Soto
Jesus Soto10mo ago
I'm taking MONGO_URL to connect but it doesn't work
No description
MantisInABox
MantisInABox10mo ago
Can you show me your environment variables in your service (app)
Jesus Soto
Jesus Soto10mo ago
In DB_CONECTION there is this url: mongodb://mongo:[my-data]@containers-us-west-184.railway.app:5712
No description
MantisInABox
MantisInABox10mo ago
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
Jesus Soto
Jesus Soto10mo ago
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".
MantisInABox
MantisInABox10mo ago
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?
Brody
Brody10mo ago
are you using mongoose?
MantisInABox
MantisInABox10mo ago
There’s the guy!
Brody
Brody10mo ago
ive seen this issue before a few times
Jesus Soto
Jesus Soto10mo ago
yes i using mongoose oh and what is the solution?
Brody
Brody10mo ago
specify the database name with that options parameter https://mongoosejs.com/docs/api/mongoose.html#Mongoose.prototype.connect()
No description
Brody
Brody10mo ago
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 variables
Jesus Soto
Jesus Soto10mo ago
ok perfect I'll do it