Socket
Socket
Sign inDemoInstall

mongoose-denorm

Package Overview
Dependencies
4
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mongoose-denorm

Simple two-way denormalization for mongoose schemas.


Version published
Maintainers
1
Install size
6.06 MB
Created

Readme

Source

Mongoose-elastic

Simple two-way denormalization for mongoose schemas.

Version

0.3

Tech

  • Mongoose

Directory Structure

|---mongoose-elastic
   |-lib
   |-test

Install

npm install mongoose-elastic --save

Setup

Add a mapping and prefix.

activitySchema.plugin(elastic, { prefix: 'dev',
  mapping: {

    message: String,
    event: {
      title: String
    }
  }
})

=======

Examples

var mongoose = require('mongoose');

var denormalize = require('./lib/denormalize');
var Mixed = mongoose.Schema.Types.Mixed;

```sh
var activitySchema = new mongoose.Schema({
  message           :   String,
  event           : { type: Mixed, ref: 'events', fields: ['title', 'uName', 'address'] },
  user            : { type: Mixed, ref: 'users', fields: ['uName'] },
});

var eventSchema = new mongoose.Schema({
  uName    : { type: String, maps: ['activities'] },
  title: { type: String, maps: ['activities'] },
  address: String,
  location: [0, 3]
})

var userSchema = new mongoose.Schema({
  uName: String,
  fullName: String
})

// automatically all data on save, not just 'changed' fields
activitySchema.plugin(denormalize, { sync: true });
userSchema.plugin(denormalize);
eventSchema.plugin(denormalize);

var Activity = mongoose.model('activities', activitySchema) var User = mongoose.model('users', userSchema) var Event = mongoose.model('events', eventSchema)

mongoose.connect('mongodb://localhost:27017/test')

// create models var event = new Event({ uName: 'eventUName', title: 'Smashboxx', address: 'Scottsdale, AZ', location: [0, 3] })

var user = new User({ uName: 'username', fullName: 'John Doe' })

/* Now just save docs and activity will be denormalized. */ var activity = new Activity({ message: 'Im denormalized! Yay!', user: user.id, event: event.id })


## Tests
-----------
```sh
make test

FAQs

Last updated on 28 Mar 2014

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