This project provides types and utilities for Mongoose v8.
- Enhanced
toJSON
method with normalization functions:- Auto-converts
_id
toid
- Removes
private
fields from the JSON output - Converts
Decimal128
fields to strings - Removes
__v
version key
- Auto-converts
- Commonly used schema settings for fast schema creation with
createCommonMongooseSchemas
. - Automatic timestamp field settings based on configuration.
- Pre-registered
mongoose-paginate-v2
andmongoose-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.
# Using pnpm
pnpm add @kikiutils/mongoose
# Using yarn
yarn add @kikiutils/mongoose
# Using npm
npm i @kikiutils/mongoose
- ESM only
- Mongoose v8
- NodeJS 18 or higher
Example code is provided in the examples folder. Follow the steps below to understand how to use the package:
- Navigate to the examples folder
cd examples
- Install the dependencies
pnpm i
- Copy the .env.example file to .env
cp .env.example .env
- Set the MONGODB_URI in the .env file with your MongoDB connection string
- 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.