Socket
Socket
Sign inDemoInstall

q3-plugin-extref

Package Overview
Dependencies
674
Maintainers
1
Versions
153
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    q3-plugin-extref

This plugin implements the [Extended Reference Pattern](https://www.mongodb.com/blog/post/building-with-patterns-the-extended-reference-pattern) to reduce lookups in your code. It connects to Mongoose's save middleware, so it will not fire on update op


Version published
Weekly downloads
16
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Extended Reference and Autopopulate Plugin

This plugin implements the Extended Reference Pattern to reduce lookups in your code. It connects to Mongoose's save middleware, so it will not fire on update operations. It also relies on Q3's archiving functionality, so it will only pull or unset on specific document changes.

// FILE #1
const  mongoose = require('mongoose');
const { ExtendedReference } = require('q3-plugin-extref');

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

// tells the plugin which collections to update on save
ReferenceSchema.plugin(ExtendedReference.plugin, [
    'TARGETS',
]);

module.exports = mongoose.model('DEMO_ONLY', ReferenceSchema);

// FILE #2
const  mongoose = require('mongoose');
const { ExtendedReference } = require('q3-plugin-extref');
const  ReferenceModel = require('./reference');

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

  // Saves as:
  // {
  //   ref: ObjectId(),
  //   name: 'Example',
  //   age: 21
  // }
});

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

Alternatively, this plugin also ships with a very basic autopopulation feature.

const  mongoose = require('mongoose');
const { autopopulate } = require('q3-plugin-extref');

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

TargetSchema.plugin(autopopulate)

FAQs

Last updated on 20 Apr 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc