@meanie/mongoose-update-denormalized

2.3.0 • Public • Published

@meanie/mongoose-update-denormalized

npm version node dependencies github issues codacy

A plugin for Mongoose to normalize JSON output

Meanie

Installation

You can install this package using yarn or npm.

#yarn
yarn add @meanie/mongoose-update-denormalized

#npm
npm install @meanie/mongoose-update-denormalized --save

Usage

Setup as a global plugin for all Mongoose schema's:

const mongoose = require('mongoose');
const updateDenormalized = require('@meanie/mongoose-update-denormalized');

mongoose.plugin(updateDenormalized);

Or for a specific (sub) schema:

const mongoose = require('mongoose');
const updateDenormalized = require('@meanie/mongoose-update-denormalized');
const {Schema} = mongoose;

const MySchema = new Schema({});
MySchema.plugin(updateDenormalized);

This plugin exposes a static method to update denormalized data:

const User = mongoose.model('User');
const {_id, name, region} = location;
await User.updateDenormalized('location', _id, {name, region});

This would update the name and region properties on the denormalized location property on users, for the given matching location ID.

Issues & feature requests

Please report any bugs, issues, suggestions and feature requests in the @meanie/mongoose-update-denormalized issue tracker.

Contributing

Pull requests are welcome! If you would like to contribute to Meanie, please check out the Meanie contributing guidelines.

Sponsor

This package has been kindly sponsored by Hello Club, an all in one club and membership management solution complete with booking system, automated membership renewals, online payments and integrated access and light control. Check us out if you happen to belong to any kind of club or if you know someone who helps run a club!

License

(MIT License)

Copyright 2016-2020, Adam Reis

Package Sidebar

Install

npm i @meanie/mongoose-update-denormalized

Weekly Downloads

7

Version

2.3.0

License

MIT

Unpacked Size

7.28 kB

Total Files

7

Last publish

Collaborators

  • adamreisnz