# mongoose-ref-promises

> A mongoose plugin which adds promise-based population virtual properties to your Models

Latest version **1.0.0** (published 2016-01-27) · 0 weekly downloads

## Install

```sh
npm install mongoose-ref-promises
pnpm add mongoose-ref-promises
yarn add mongoose-ref-promises
bun add mongoose-ref-promises
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-01-27 |
| First published | 2013-12-03 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Pedro Yamada |
| Maintainers | yamadapc |
| Keywords | mongoose, promises, references, relations |

## Links

- npm: https://www.npmjs.com/package/mongoose-ref-promises
- Repository: https://github.com/yamadapc/mongoose-ref-promises
- Issues: https://github.com/yamadapc/mongoose-ref-promises/issues
- npm.io page: https://npm.io/package/mongoose-ref-promises

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.0.1
- [bluebird](https://npm.io/package/bluebird.md) ^3.1.5

## 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
- [@temporal-architect/claude-plugin](https://npm.io/package/@temporal-architect/claude-plugin.md) — 335 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-01-27
- 0.2.0 — 2014-09-19
- 0.1.2 — 2014-09-03
- 0.1.1 — 2014-03-05
- 0.1.0 — 2014-02-24
- 0.0.3 — 2014-02-06
- 0.0.2 — 2014-02-04
- 0.0.1 — 2013-12-03

## README

mongoose-ref-promises
=====================
[![Build Status](https://secure.travis-ci.org/yamadapc/mongoose-ref-promises.png?branch=master)](http://travis-ci.org/yamadapc/mongoose-ref-promises)
[![Code Climate](https://codeclimate.com/github/yamadapc/mongoose-ref-promises.png)](https://codeclimate.com/github/yamadapc/mongoose-ref-promises)
[![Coverage Status](https://coveralls.io/repos/yamadapc/mongoose-ref-promises/badge.png)](https://coveralls.io/r/yamadapc/mongoose-ref-promises)
[![Dependency Status](https://david-dm.org/yamadapc/mongoose-ref-promises.svg)](https://david-dm.org/yamadapc/mongoose-ref-promises)
[![devDependency Status](https://david-dm.org/yamadapc/mongoose-ref-promises/dev-status.svg)](https://david-dm.org/yamadapc/mongoose-ref-promises#info=devDependencies)
[![Analytics](https://ga-beacon.appspot.com/UA-54450544-1/mongoose-ref-promises/README)](https://github.com/igrigorik/ga-beacon)
- - -
A mongoose plugin which adds promise-based population virtual properties to your
Models

## Installation
Install the module with: `npm install mongoose-ref-promises`

Use it by adding it as a plugin to any mongoose.Schema

```javascript
// [...]
var refPromises = require('mongoose-ref-promises');
UserSchema.plugin(refPromises);
// [...]
```

## Examples

The plugin adds virtual properties to each 'ref' property in your schema.

Say we have this setup.

```javascript
var mongoose = require('mongoose'),
    Schema   = mongoose.Schema,
    ObjectId = Schema.ObjectId;

var refPromises = require('mongoose-ref-promises');

var UserSchema = new Schema({
  friends: [{ type: ObjectId, ref: 'User' }],
  bff:      { type: ObjectId, ref: 'User' }
});
UserSchema.plugin(refPromises);

var User = mongoose.model('User', UserSchema);
```

We can than access the virtual properties ```friendsP``` and ```bffP``` of any
'User' document.

*i.e.*

```javascript
// [...]
user.friendsP
  .then(function(friends) {
    // [...]
  });
```

or

```javascript
// [...]
user.bffP
  .then(function(best_friend_forever) {
    // [...]
  });
```

## License
Copyright (c) 2014 Pedro Yamada. Licensed under the MIT license.

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