1.0.0 • Published 10 years ago

mongoose-ref-promises v1.0.0

Weekly downloads
1
License
-
Repository
github
Last release
10 years ago

mongoose-ref-promises

Build Status Code Climate Coverage Status Dependency Status devDependency Status Analytics


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

// [...]
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.

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.

// [...]
user.friendsP
  .then(function(friends) {
    // [...]
  });

or

// [...]
user.bffP
  .then(function(best_friend_forever) {
    // [...]
  });

License

Copyright (c) 2014 Pedro Yamada. Licensed under the MIT license.

1.0.0

10 years ago

0.2.0

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.3

11 years ago

0.0.2

12 years ago

0.0.1

12 years ago