Change MongoDB default database name

guestman360TRIAL

2 years ago

Hello, I have a question, can I change mongodb default database name? Its "test" right now. I'd preferably like to name it something like "prod". How can I do this?

0 Replies

2 years ago

just hit the little plus button and add a database named "prod"


guestman360TRIAL

2 years ago

I see, but then how can I fill that database with data? If I have both a "test" and a "prod" database how does my request create collections in the correct database.

Also, is there a way to copy over data from the test to the prod db? I already have a bunch of data that I don't want to recreate manually if possible.


2 years ago

  1. youd specify the database you want to use when connecting to mongo

  2. youd have to mongodump test and mongorestore the dump to prod


guestman360TRIAL

2 years ago

Do you have any examples for how to do the mongodump test and mongorestore? I'm not too sure how I would be able to interact and run these commands with the database in railway


2 years ago


guestman360TRIAL

2 years ago

thank you, I'll let you know if I have more questions


webdynamics-devHOBBY

a year ago

hello… i seem to have the same problem except…. when i create a new database and enter the new db name in the connection string i get the error "Authentication failed"


a year ago

please read the mongoose docs, you need to specify the database name in the connection options


webdynamics-devHOBBY

a year ago

according to mongo specs, the connection string should be mongodb://[username:password@]host1[:port1][/[defaultauthdb][?options]]
this is exactly what i'm doing, appending the new db name to the private connection string provided by railway… am I missing something?


a year ago

as mentioned previously, please read mongoose docs, you need to specify the database name in the connection object, not the url


webdynamics-devHOBBY

a year ago

got it… thanks!


Change MongoDB default database name - Railway Help Station