This package has been deprecated

Author message:

use mongoose-populate-virtuals instead

mongoose-power-populate

1.3.4 • Public • Published

mongoose-power-populate

"Join" mongoose documents. Recursively populate document references in either direction.

DEPRECATED: Use Mongoose 4+ and mongoose-populate-virtuals instead.

Usage

Wrap mongoose to provide an improved populate() method:

var mongoose = require('mongoose');
var populatePlugin = require('mongoose-power-populate')(mongoose);

Populate paths with predefined options:

Book.find().populate('author reviews').exec(...);

Specify options for population paths on the model:

BookSchema.plugin(populatePlugin, {
    author: {
      ref: 'User',
      foreignKey: '_id',
      localKey: 'authorId',
      select: 'name',
      lean: true,
      singular: true
    }
});

Populate nested paths:

User
  .find(...)
  .populate({
    'posts': { ... },
    'posts.comments': { ... }
  })
  .exec(...);

Override options at query time:

Book
  .find()
  .populate({
    author: {
      select: 'name isbn'
    }
  })
  .exec(...);

Populate existing documents:

Book.populate(docs, 'author', callback);

Options

  • ref Name of the mongoose model.
  • foreignKey Key on the model of the populated subdocuments.
  • localKey Key on the model being populated.
  • singular Whether to return a single result or an array of results.
  • lean Whether to populate with models or plain objects.
  • query Specify the find() query used to fetch related documented.
  • select Passed to mongoose's .select().

Package Sidebar

Install

npm i mongoose-power-populate

Weekly Downloads

0

Version

1.3.4

License

ISC

Last publish

Collaborators

  • alexmingoia
  • buildingconnected