New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-denorm

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-denorm

Simple two-way denormalization for mongoose schemas.

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
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

Package last updated on 28 Mar 2014

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc