autopopulate
v1.0.3
Published
A simple plugin to populate documents in mongodb.
Downloads
4
Readme
Package by Ujwal
Installation
To install this package, use npm:
npm install autopopulate
Usage
Here is an example of how to use the package in your project
var mongoose = require("mongoose");
var autopopulate = require("autopopulate");
var xyzSchema = new mongoose.Schema({
author: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Users'
},
time: String,
content: String
});
var options = {
// Your options here
};
xyzSchema.plugin(autopopulate, options);
var xyz = mongoose.model("xyz", xyzSchema);
Parameters
options is an optional object with an applyOn field to instruct the plugin on which operations to apply it.
It can accept the following values: all
find
findOne
findById
The default value is all
if you do not specify it.
ExampleTo use the package with specific options:
var options = {
applyOn: 'findOne'
};
xyzSchema.plugin(autopopulate, options);
//This will apply the autopopulate plugin only on findOne operations.