Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Mini population hook for Mongoose so you don't need to keep rewriting this.populate and next.

License

Notifications You must be signed in to change notification settings

dacioromero/mongoose-populate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mongoose Populate

npm bundle size npm GitHub GitHub top language GitHub Workflow Status (branch)

Mini population hook for Mongoose so you don't need to keep rewriting this.populate and next.

Installation

$ npm install mongoose-populate

CommonJS

const { Schema } = require('mongoose')
const { createPopulateHook } = require('mongoose-populate')

ESM

import { Schema } from 'mongoose'
import { createPopulateHook } from 'mongoose-populate'

Schema

const ExampleSchema = new Schema({
    example: {
        type: Schema.Types.ObjectId,
        ref: 'OtherModel',
    },
})

Hook replacement

- ExampleSchema.pre('find', function populateExampleHook(next) {
-   this.populate('example');
-   next();
- });

+ ExampleSchema.pre('find', createPopulateHook('example'));

About

Mini population hook for Mongoose so you don't need to keep rewriting this.populate and next.

Topics

Resources

License

Stars

Watchers

Forks

Packages