Change MongoDB default database name

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?
12 Replies
Percy
Percy2y ago
Project ID: N/A
Brody
Brody2y ago
just hit the little plus button and add a database named "prod"
Len-goo-uh
Len-goo-uhOP2y 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.
Brody
Brody2y 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
Len-goo-uh
Len-goo-uhOP2y 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
Len-goo-uh
Len-goo-uhOP2y ago
thank you, I'll let you know if I have more questions
vlado@webdynamics
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"
Brody
Brody10mo ago
please read the mongoose docs, you need to specify the database name in the connection options
vlado@webdynamics
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?
Brody
Brody10mo ago
as mentioned previously, please read mongoose docs, you need to specify the database name in the connection object, not the url
vlado@webdynamics
got it... thanks!
Want results from more Discord servers?
Add your server