# mangomodel

> A simple mongo db model maker

Latest version **0.0.5** (published 2012-10-02) · BSD license · 2 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score; declining downloads.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2012-10-02 |
| First published | 2012-09-27 |
| Weekly downloads | 2 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Node | v0.8.x |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| Author | Coen Hyde |
| Maintainers | coen-hyde |
| Keywords | mongodb, monk |

## Links

- npm: https://www.npmjs.com/package/mangomodel
- Repository: https://github.com/coen-hyde/mangomodel
- npm.io page: https://npm.io/package/mangomodel

## Dependencies (3)

- [monk](https://npm.io/package/monk.md) 0.3.x
- [moment](https://npm.io/package/moment.md) 1.7.x
- [revalidator](https://npm.io/package/revalidator.md) 0.1.x

## 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.0.5 (latest) — 2012-10-02
- 0.0.4 — 2012-09-28
- 0.0.3 — 2012-09-28
- 0.0.2 — 2012-09-27
- 0.0.1 — 2012-09-27

## README

MangoModel
==========

MangoModel is not an ORM. It is a very simple wrapper over the Monk MongoDb library. MangoModel's main purpose is to allow dynamic db switching and data validation.

Using MangoModel
----------------

```js
// Create db connection
var db = Monk('host/db');

// Create model
var Ant = MangoModel.create(db, 'ants');

// Accessing your model
var Ant = MangoModel.model('ants');

// Set the global db object so you don't have to specify the db every time you define a model
MangoModel.setDb(db);

var Rat = MangoModel.create('rats');
```

Dynamic DB switching
--------------------

When providing the database connection to either a model or the global MangoModel, you can provide a function that returns the database connection. This allows you to switch the database out as required.

Defining methods on your model
------------------------------

```js
var Cat = MangoModel.create('cats', {
  methods:
    getFatCats: function(cb) {
      this.find({weight: {'$gt':30}}, cb);
    }
  }
});

var cats = Cat.getFatCats(function(err, cats) {
  // variable cats is an array of cat objects
});
```

Defining a schema for data validation
-------------------------------------

// TODO

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