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

MikeIbberson/mongoose-field-populate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💫 Mongoose Extended Reference and Autopopulate

Status Coverage Status

Extended Reference

The extended reference builder provides a plugin for managing stale data updating as well as a builder for assembling extended references. It auto-syncs the target props on save, so you don't have to worry about matching types, setting projects and more.

  const mongoose = require('mongoose');
  const { ExtendedReference } = require('mongoose-field-populate');

  const ReferenceSchema = new mongoose.Schema({
    name: String,
    age: Number,
  });

  ReferenceSchema.plugin(ExtendedReference.plugin, [
    'TARGETS',
  ]);

  module.exports = mongoose.model('DEMO_ONLY', ReferenceSchema);
  const mongoose = require('mongoose');
  const { ExtendedReference } = require('mongoose-field-populate');
  const ReferenceModel = require('./reference');

  const TargetSchema = new mongoose.Schema({
    friend: new ExtendedReference(ReferenceModel)
      .on(['name', 'age'])
      .set('name', { private: true })
      .done(),
  });

  module.exports = mongoose.model('TARGETS', TargetSchema);

Autopopulate

This package also ships with a very basic autopopulation feature. The most common solution on NPM does not suit my needs, though it might fit nicely into your project. Use this only if you require autopopulation on discriminators or embedded arrays.

  const mongoose = require('mongoose');
  const { autopopulate } = require('mongoose-field-populate');
  
  const TargetSchema = new mongoose.Schema({
    email: {
      type: String,
      unique: true,
      autopopulate: true,
      autopopulateSelect: 'projection path',
    }
  });

  TargetSchema.plugin(autopopulate)

About

Mongoose plugin for autopopulation ⛔️ DEPRECATED

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published