Database Connection Options
Here are the environment variables you can use to configure your database connection:DB_ADAPTER
The adapter handles the MongoDB connection. You can choose between:
default- Uses the official MongoDB package for productionmock- Uses mongo-mock which is perfect for testing
default
DB_URL
The connection URL for your MongoDB database.
Default: mongodb://127.0.0.1:27017/
Example:
DB_MAX_POOL_SIZE
The maximum number of connections in the connection pool. This helps manage
database performance under load.
Default: 10
DB_DATABASE
The name of the database to connect to.
Default: (empty string)
Example:
DB_LOG_QUERIES
Enables the built-in query logger. When set to 1 or true, Esix logs every
MongoDB operation to the console using console.debug, including the
collection, operation, arguments, and duration.
Default: (disabled)
Example:
Setting Up Environment Variables
For local development, we recommend using the dotenv package to manage your environment variables:.env file in your project root:
⚠️ Security Note: Never commit secrets or production credentials to version control. Add.envto your.gitignorefile!
Query Logging
Query logging is opt-in and has zero overhead when disabled. The quickest way to turn it on is theDB_LOG_QUERIES environment variable, which logs every
MongoDB operation with console.debug:
setQueryLogger. The custom logger takes precedence over the built-in console
logger:
args- the arguments passed to the driver methodcollectionName- the collection the operation ran againstdurationMs- how long the operation took, in millisecondserror- the error the operation rejected with, if anyoperation- the driver method that was invoked, e.g.findorupdateOne
null to clear the custom logger again:
