Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yamadapc/mongoose-ref-promises
A mongoose plugin which adds promise-based ref population virtuals to your Models
https://github.com/yamadapc/mongoose-ref-promises
Last synced: 2 months ago
JSON representation
A mongoose plugin which adds promise-based ref population virtuals to your Models
- Host: GitHub
- URL: https://github.com/yamadapc/mongoose-ref-promises
- Owner: yamadapc
- License: mit
- Created: 2013-12-03T18:39:09.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-04-05T02:23:14.000Z (almost 9 years ago)
- Last Synced: 2024-10-21T05:08:06.654Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 15.6 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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.## Donations
Would you like to buy me a beer? Send bitcoin to 3JjxJydvoJjTrhLL86LGMc8cNB16pTAF3y