Skip to content

MongoDB - variables for connecting to the DB #192

@folive3

Description

@folive3

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions