Skip to content

Repository files navigation

Mongoloquent Sample — NestJS

Example implementation of Mongoloquent in a NestJS application, demonstrating all supported relationship types.

Relationships Covered

Relationship Example
hasMany User → Posts
hasOne User → Phone
belongsTo Post → User
belongsToMany User ↔ Roles (pivot: role_user)
hasManyThrough Application → Deployments through Environments
morphOne User/Post → Image (imageable)
morphMany Post/Video → Comments (polymorphic)
morphTo Comment/Image → commentable/imageable
morphToMany Post/Video → Tags (polymorphic pivot: taggable)
morphedByMany Tag → Posts/Videos (inverse of morphToMany)

Prerequisites

  • Node.js
  • MongoDB instance (local or remote)

Project Setup

$ npm install

Copy .env.example to .env and configure your MongoDB connection:

MONGODB_URI=mongodb://localhost:27017
MONGODB_DB_NAME=sample-nestjs
MONGODB_TIMEZONE=Asia/Jakarta

Running the App

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

API Documentation

Swagger UI is available at http://localhost:3000/docs after starting the app.

Run Tests

# unit tests
$ npm run test

# test coverage
$ npm run test:cov

# e2e tests
$ npm run test:e2e

Unit tests cover all controller endpoints and service methods using mocked models and services. No database connection is required.

Resources

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages