# mongoose-model

> Define your mongoose models easily with Typescript

Latest version **0.7.2** (published 2019-05-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install mongoose-model
pnpm add mongoose-model
yarn add mongoose-model
bun add mongoose-model
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.2 |
| Published | 2019-05-27 |
| First published | 2017-05-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 82.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Alexey Prokhorov |
| Maintainers | megahertz |
| Keywords | mongoose, odm, model, typescript, decorator |

## Links

- npm: https://www.npmjs.com/package/mongoose-model
- Repository: https://github.com/megahertz/mongoose-model
- Homepage: https://github.com/megahertz/mongoose-model#readme
- Issues: https://github.com/megahertz/mongoose-model/issues
- npm.io page: https://npm.io/package/mongoose-model

## Dependencies (1)

- [reflect-metadata](https://npm.io/package/reflect-metadata.md) *

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.7.2 (latest) — 2019-05-27
- 0.7.1 — 2019-05-14
- 0.7.0 — 2019-05-14
- 0.6.0 — 2019-05-14
- 0.5.5 — 2019-05-14
- 0.5.4 — 2019-05-14
- 0.5.3 — 2019-05-14
- 0.5.2 — 2019-05-11
- 0.5.0 — 2019-05-11
- 0.4.0 — 2019-04-24
- 0.3.9 — 2019-04-22
- 0.3.8 — 2019-02-13
- 0.3.7 — 2018-12-05
- 0.3.6 — 2018-12-05
- 0.3.5 — 2018-12-05
- … 24 more at https://npm.io/package/mongoose-model/versions

## README

# mongoose-model
[![Build Status](https://travis-ci.org/megahertz/mongoose-model.svg?branch=master)](https://travis-ci.org/megahertz/mongoose-model)
[![NPM version](https://badge.fury.io/js/mongoose-model.svg)](https://badge.fury.io/js/mongoose-model)
[![Dependencies status](https://david-dm.org/megahertz/mongoose-model/status.svg)](https://david-dm.org/megahertz/mongoose-model)

## Installation

Install with [npm](https://npmjs.org/package/mongoose-model):

    npm install mongoose-model
    
## Usage

```typescript
import { def, Model, model, prop, Query, ref } from 'mongoose-model';

export interface IContact {
  kind: string;
  value: string;
}

@model
export class User extends Model {
  @prop age: number;
  @prop({
    kind: String,
    value: String,
  })
  contacts: IContact[];
  @prop createdAt: Date;
  @prop email: string;
  @def(false) isActive: boolean;
  @prop name: string;

  get displayName() {
    return `${this.name} <${this.email}>`;
  }

  static findByEmail(email: string): Query<User> {
    return this.findOne({ email });
  }
}

@model
export class Post extends Model {
  @prop body: string;
  @ref  creator: User;
  @prop title: string;

  static findByTitle(title: string): Query<Post> {
    return this.findOne({ title });
  }
}
```

---
_Source: https://npm.io/package/mongoose-model · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
