@kikiutils/mongoose

1.0.1 • Public • Published

@kikiutils/mongoose

npm version npm downloads License

This project provides types and utilities for Mongoose v8.

Features

  • Enhanced toJSON method with normalization functions:
    • Auto-converts _id to id
    • Removes private fields from the JSON output
    • Converts Decimal128 fields to strings
    • Removes __v version key
  • Commonly used schema settings for fast schema creation with createCommonMongooseSchemas.
  • Automatic timestamp field settings based on configuration.
  • Pre-registered mongoose-paginate-v2 and mongoose-aggregate-paginate-v2 plugins for pagination support.
  • Automatic Decimal128 field conversion and rounding configuration.
  • TypeScript support for better type safety and IntelliSense.
  • Flexible model creation with buildMongooseModel, supporting custom connections and plugin configurations.

Installation

# Using pnpm
pnpm add @kikiutils/mongoose

# Using yarn
yarn add @kikiutils/mongoose

# Using npm
npm i @kikiutils/mongoose

Environmental Requirements

  • ESM only
  • Mongoose v8
  • NodeJS 18 or higher

Usage

Example code is provided in the examples folder. Follow the steps below to understand how to use the package:

  1. Navigate to the examples folder
cd examples
  1. Install the dependencies
pnpm i
  1. Copy the .env.example file to .env
cp .env.example .env
  1. Set the MONGODB_URI in the .env file with your MongoDB connection string
  2. Run the example code
  • If you use bun, run this command directly

    bun --watch run ./src/index.ts
  • Use node

    pnpm run build
    MONGODB_URI="mongodb://127.0.0.1:27017/kikiutils-mongoose-test?directConnection=true" node ./dist/index.mjs

This will execute the example code and demonstrate how to use the @kikiutils/mongoose package with your MongoDB setup.

You can modify the code in examples/src/index.ts and run it to test other functions.

License

MIT License

Package Sidebar

Install

npm i @kikiutils/mongoose

Weekly Downloads

187

Version

1.0.1

License

MIT

Unpacked Size

74 kB

Total Files

21

Last publish

Collaborators

  • kiki-kanri