1.3.4 • Published 9 years ago

mongoose-power-populate v1.3.4

Weekly downloads
1
License
ISC
Repository
github
Last release
9 years ago

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().
1.3.4

9 years ago

1.3.3

9 years ago

1.3.2

9 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago