The Ferreandina backend reads all runtime configuration from aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tutosrive/ferreandina-nosql/llms.txt
Use this file to discover all available pages before exploring further.
.env file using the dotenv-java library. The .env file is loaded inside Connection.java the moment any controller opens its first MongoDB collection — no system-level environment variables or JVM flags are needed.
Environment Variables
Both variables are required. The application will throw an exception at startup if either is missing from the.env file.
The full MongoDB connection string. Use
mongodb://localhost:27017 for a local instance or a mongodb+srv://... URI for MongoDB Atlas.The name of the MongoDB database to connect to, e.g.
ferreandina. The database will be created automatically by MongoDB if it does not already exist..env file example
Place this file inapp/bc/ (the same directory where you run ./gradlew run):
MongoDB Connection
Connection<T extends Model> is a generic class that encapsulates the full lifecycle of a MongoDB connection for a single collection. When constructed it:
- Loads
.envviaDotenv.load()and readsMONGODB_URIandMONGODB_DB_NAME. - Calls
createProviders()to build a POJO-awareCodecRegistry. - Calls
initMongo()to create theMongoClientand obtain aMongoDatabasereference with the custom codec applied.
setCollection(name) to bind the connection to a specific MongoDB collection, storing it in the public collection field for direct use by the service layer.
POJO Codec Configuration
ThecreateProviders() method registers a PojoCodecProvider built with .automatic(true). This instructs the MongoDB driver to automatically map BSON documents to and from any Java POJO it encounters — no manual field mapping or custom codecs are required for model classes.
CodecRegistry is composed from two layers:
MongoClientSettings.getDefaultCodecRegistry()— handles all primitive types,ObjectId,BsonValue,Date, etc.fromProviders(customClassBuilder)— handles automatic POJO serialization for model classes (e.g.,BranchModel,ProductModel).
MongoDatabase instance via withCodecRegistry(this.customCodec), so every collection opened from that database inherits POJO support automatically.
CORS
App.java enables CORS globally using Javalin’s bundled plugin, configured with anyHost():
MongoDB Atlas
To connect to a cloud-hosted Atlas cluster, replaceMONGODB_URI with the Atlas connection string found in the Connect dialog of your cluster. No code changes are needed — Connection.java uses the URI as-is.
0.0.0.0/0 for unrestricted access during development.