This package has been deprecated

Author message:

This project is no longer supported. I'm bringing it into a larger framework, Q3, where I will support and evolve it.

mongoose-field-populate

2.2.10 • Public • Published

💫 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)

Readme

Keywords

none

Package Sidebar

Install

npm i mongoose-field-populate

Weekly Downloads

1

Version

2.2.10

License

MIT

Unpacked Size

47.2 kB

Total Files

45

Last publish

Collaborators

  • 3merge