New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

mongoose-backref

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-backref

A back reference plugin for mongoosejs

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

This is a Mongoose plugin that handles back references. You can define a back reference on any references or array of references in the source Schema. Whenever the a document of the source Schema type has that field changed, the target document will have its back references updated:

Foo {bar: {ref: 'Bar', backref: 'foos'}} Bar {foos: [{ref: 'Foo'}]}

In the above, anytime Foo.bar is changed, the related Bar.foos is updated. Note that this is not bi-directional! If Bar.foos is changed, Foo.bar is NOT updated. In order to do that, you need to define a reverse back reference:

Foo {bar: {ref: 'Bar', backref: 'foos'}} Bar {foos: [{ref: "Foo', backref: 'bar'}]}

In the above, any updates to Foo.bar is same as before, but in addition, any changes to Bar.foos get updated too (in this case, if a Foo is removed from Bar.foos, that Foo's Foo.bar will be set to null). Note that in this particular instance, you want to really make sure this is the right behavior for your model relationship. For example, as defined above, one could add the same Foo to multiple Bar.foos, in which case the last Bar that added Foo would have it referenced in Foo.bar. In order to deal with this, you might want to have a many-to-many relationship:

Foo {bars: [{ref: 'Bar', backref: 'foos'}]} Bar {foos: [{ref: "Foo', backref: 'bars'}]}

In this case, Foo.bars is an array of references, so many-to-many relationships are supported.

Keywords

mongodb

FAQs

Package last updated on 02 Nov 2016

Did you know?

Socket

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