JCC Express

Mongoose

Introduction

JCC Express MVC supports MongoDB through a Mongoose driver (MongooseDriver) selected by database config/env.

When enabled, the framework resolves and registers the Mongoose connection as:

  • database.connection
  • mongoose

Enable Mongoose

Set env values for mongo mode:

env

app/Config/database.ts includes the expected mongoose block:

TypeScript

Required packages

Install Mongoose:

Bash

Do not manually write model files. Use ArtisanNode:

Bash

Keep your Mongo-oriented model definitions in app/Models so the project structure stays consistent.


Mongoose model example

In Mongoose mode, a model file can follow this shape:

TypeScript

The exported model name User is important in this project for route model binding conventions.


Connection behavior

From MongooseDriver:

  • builds URI as mongodb://[username:password@]host:port/database
  • runs mongoose.connect(uri, options)
  • keeps a shared connection reference for the app lifecycle

Disconnect path uses mongoose.disconnect().


Access the Mongoose connection

TypeScript

The instance is registered by DatabaseServiceProvider.


Notes

  • Driver selection is triggered by DB_ORM=mongoose or DB_CONNECTION=mongodb.
  • If host/database are missing, URI construction fails and connect throws.
  • Keep Mongo-specific schema/model logic separate from SQL/JCC query-builder code paths.

Summary

  • Set DB_ORM=mongoose.
  • Configure the mongoose section in app/Config/database.ts.
  • Install mongoose.
  • Generate models with bun artisanNode make:model User.
  • Resolve connection via app.resolve("mongoose").