README
mongodbext-relations
mongodbext plugin that bring relations between collections
Starting from mongodbext-relations@2.x
supports mongodb 3.6+ only
options:
relations
(required) - hash of fields that should be embedded, should be specified in format:{field1: field1Options, field2: fieldOptions, ...}
. Each field options could have properties:collection
(required) - instance of mongodbext collection, that should be embeddedprojection
- fields projection to embed ({_id: 1}
by default`)key
- "primary key" field (_id
by default)embedded
- function that used to create EmbeddedDocument instance (autogenerated by default)onDelete
- action that should be done on embedded document deletion, available actions: 'restrict', 'cascade', 'unset', 'pull', null ('restrict' by default)onUpdate
- action that should be done on embedded document updation, available actions:cascade
, null ('cascade' by default)
Example:
var MongoClient = require('mongodb').MongoClient;
var mongodbext = require('mongodbext');
var mongodbextRelations = require('mongodbext-relations');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
var authorsCol = new mongodbext.Collection(db, 'authors');
var chaptersCol = new mongodbext.Collection(db, 'chapters');
var booksCol = new mongodbext.Collection(db, 'books');
booksCol.addPlugin(mongodbextRelations, {
relations: {
'author': {
collection: authorsCol,
projection: {_id: 1, name: 1}
},
'chapters.