Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDB - variables for connecting to the DB #192

Open
folive3 opened this issue Aug 22, 2023 · 0 comments
Open

MongoDB - variables for connecting to the DB #192

folive3 opened this issue Aug 22, 2023 · 0 comments

Comments

@folive3
Copy link

folive3 commented Aug 22, 2023

Problem Description

In the mongo.js file, two environment variables are defined: $MONGO_DATABASE and $MONGO_CONN_STR.
When creating the .env file, if the $ character is used to name the variables, the dotenv and sugar-env libraries won't be able to locate them. As a result, the connection to the database won't be established.
Variable names in .env files should not start with the $ character, as this is not in line with best practices. Therefore, when using MongoDB, in addition to creating the .env file with the variables and their values, it's also necessary to edit the mongo.js file to remove the $ character.

Steps to Reproduce

Create a new project as shown below:
herbs new Project Config

Example of generated mongo.js file
MongoJS Default Values

Suggested correction:

Remove the $ character from the variables in the mongo.ejs template file.
Implement the automatic creation of the .env file, which by default can contain the same fallback values for their respective variables (similar to what's done in mongo.ejs), as shown in the example below:

.env
MONGO_DATABASE='<%- props.dbName %>'
MONGO_CONN_STR=mongodb://localhost:27017

This will ensure that the variable names comply with naming guidelines and that the libraries can properly load the environment variables. Additionally, the automatic creation of the .env file will streamline the configuration process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant