# mongur

> Define MongoDB models and query data using Typescript/ES6 classes.

Latest version **0.0.4** (published 2023-01-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install mongur
pnpm add mongur
yarn add mongur
bun add mongur
```

## 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.0.4 |
| Published | 2023-01-22 |
| First published | 2023-01-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 111.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | sha256 |

## Links

- npm: https://www.npmjs.com/package/mongur
- Repository: https://github.com/sha256/Mongur
- npm.io page: https://npm.io/package/mongur

## Dependencies (2)

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

## Recent versions

- 0.0.4 (latest) — 2023-01-22
- 0.0.3 — 2023-01-19
- 0.0.2 — 2023-01-19
- 0.0.1 — 2023-01-19

## README

# Mongur
Define MongoDB models and query data using Typescript/ES6 classes.


**Note:** It needs a lot more tests before it's ready for use in production.

## Documentation
[https://mongur.dev](https://mongur.dev)

## Install
```shell
# npm 
npm install mongur --save

# yarn
yarn add mongur

# pnpm
pnpm add mongur
```

## Guides
- [Define your models](https://mongur.dev/models)
- [Write queries](https://mongur.dev/queries)
- [API reference](https://mongur.dev/reference/api)


## Basic Usage

Define your models:

```typescript
import {model, Model} from "mongur"

@model()
export class User extends Model<User>() {

  @field()
  firstName!: string;

  @field()
  lastName!: string;
  
  @field()
  email!: string
  
  @field()
  password?: string

}
```

**Connect:**

```typescript
import {connection} from "mongur";
await connetion.connect("mongodb://127.0.0.1:27017/mongur")

```

**Insert:**

```typescript
const user = new User({firstName: "John", lastName: "Doe", email: "john@example.com"})
await user.save()
```

**Query:**

```typescript
const user = await User.find({email: "john@example.com"}).one()
```

**Update:**

```typescript
await User.find({email: "john@example.com"}).update({$set: {email: "john@example.net"}})
```

**Delete:**

```typescript
await User.find({email: "john@example.com"}).delete()
```


## Motivation

```typescript
// Mongoose example
const User = model<IUser>('User', userSchema);
// Typegoose example
const User = getModelForClass(ModelClass);
```
Here, in both cases `User` is not a type, it's a value. Therefore, it cannot be used to specify type in the code.
For example, you cannot define a function like this:

```typescript

function doSomething(user: User) { // Error, 'User' refers to a value, but is being used as a type here

}
```
Many people counter this problem by writing an interface with the same fields (`Declaration Merging`). Others just 
use `any` type instead. `Mongur` solves this problem by defining schema using pure class and using the same class for
querying data.

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