populate() certain fields in your mongoose schemas
Note: This plugin will only work with mongoose >= 4.0. Do NOT use this plugin with mongoose 3.x. You have been warned.
Note: population is a powerful feature, but it has limitations and helps you get away with poor schema design. In particular, it is usually bad MongoDB schema design to include arrays that grow without bound in your documents. Do not include a constantly-growing array of ObjectIds in your schema - your data will become unwieldy as the array grows and you will eventually hit the 16 MB document size limit. In general, think carefully when designing your schemas.
mongoose-autopopulate module exposes a single function that you can
pass to Mongoose schema's
const schema =populatedField:type: mongooseSchemaTypesObjectIdref: 'ForeignModel'// The below option tells this plugin to always call `populate()` on// `populatedField`autopopulate: true;schema;
Only apply this plugin to top-level schemas. Don't apply this plugin to child schemas.
// Don't do `nestedSchema.plugin(require('mongoose-autopopulate'))`.// You only need to add mongoose-autopopulate to top-level schemas.const nestedSchema = mongoose;const topSchema = mongoose;topSchema;