🗄️Create simple and clean class-based Mongoose schemas with TypeScript decorators.
- Lightweight
- Class based schemas
- Easy usage with TS decorators
Using npm:
npm install mondec
Using yarn:
yarn add mondec
Using pnpm:
pnpm add mondec
You need to enable emitting decorator metadata in your Typescript config. Add these two lines to your tsconfig.json file under the compilerOptions key:
"emitDecoratorMetadata": true,
"experimentalDecorators": true
import mongoose from 'mongoose'
import { Prop, Schema, SchemaFactory } from 'mondec'
@Schema({
versionKey: false
})
class User {
@Prop({
type: String,
unique: true,
required: true
})
public username!: string
@Prop({
type: Number
})
public age!: number
}
const UserSchema = SchemaFactory.createForClass(User)
const UserModel = mongoose.model('users', UserSchema)
type UserDocument = ReturnType<(typeof UserModel)['hydrate']>
- Fork this repository.
- Create a new branch with feature name.
- Create your feature.
- Commit and set commit message with feature name.
- Push your code to your fork repository.
- Create pull request.