Closed benevbright closed 3 years ago
@nishi-ai I've deployed a production DB using MongoDB Atlas (free remote mongodb platform)
We can connect to this instance by following
mongosh "mongodb+srv://cluster0.ddfbs.mongodb.net/softball" --username root
The password is XXX
.
url: mongodb+srv://cluster0.ddfbs.mongodb.net/softball
Once all the mongodb setup on Node.js is done, we can use this url for the production server to connect.
when using this mongodb url from mongoose
, it's mongodb+srv://__USERNAME__:__PASSWORD__@cluster0.ddfbs.mongodb.net/softball
Please ask me what's username and password.
@nishi-ai I've added username
and password
of our mongoDb production on Heroku console using "Heroku Config vars" https://devcenter.heroku.com/articles/config-vars. it's the same thing with the local environment variable.
What does this mean? It means that Heroku will set process.env.MONGODB_USERNAME
and process.env.MONGODB_PASSWORD
at the deployment. So in our node code, we can use these environment variables. (make sure to use them when process.env.NODE_ENV
is "production"
)
Note that these variables will be undefined
on development.
We need to find a cheap solution to have a mongoDB instance.