Skip to content

A Mongoose plugin for enhanced JSON normalization and common schema creation, with built-in support for pagination and automatic Decimal128 conversion.

License

Notifications You must be signed in to change notification settings

kiki-kanri/kikiutils-node-mongoose

Repository files navigation

@kikiutils/mongoose

npm version npm downloads License

A Mongoose plugin for enhanced JSON normalization and common schema creation, with built-in support for pagination and automatic Decimal128 conversion.

Features

  • ✨ Flexible Connections: Choose to use a specific connection or fall back to a default connection, with an automatic creation of a connection if none is provided
  • ✨ Plugin Integration: Automatically integrates mongoose-aggregate-paginate-v2, mongoose-paginate-v2, and a custom normalization plugin for enhanced JSON output
  • 🛠 Predefined Schemas: Provides a set of commonly used schema definitions such as boolean, decimal128, number, objectId, and string
  • 🛠 Customizable: Allows for custom schemas and settings, including automatic rounding and fixed decimal places for Decimal128 fields
  • 🔄 Enhanced JSON Output: Adds an id field, removes _id and __v fields, excludes private fields, and converts Decimal128 fields to strings in JSON output
  • 🧩 Reference Schema Creation: Easily create schema definitions for ObjectId references with attributes like private, required, and unique
  • 🧩 String Schema Creation: Generate string schema definitions with attributes such as private, required, short, trim, and unique
  • 🧩 Decimal128 Field Conversion: Set up getters to convert Decimal128 fields to strings for easier handling in documents
  • 🧩 Document Conversion: Convert documents or ObjectIds to documents using specified models, with optional field selection

Environment Requirements

  • Mongoose version 8.x
  • Node.js version 18 or higher

Installation

Add dependency (example using pnpm).

pnpm add @kikiutils/mongoose

You can also use yarn, npm, or bun to add the dependency.

That's it! You're ready to use this package in your project. Check out the usage instructions below ✨.

Usage

Please refer to the examples folder for usage instructions of this package.

License

MIT License

About

A Mongoose plugin for enhanced JSON normalization and common schema creation, with built-in support for pagination and automatic Decimal128 conversion.

Resources

License

Stars

Watchers

Forks