@meanie/mongoose-update-denormalized
v2.3.0
Published
A plugin for Mongoose to update denormalized data
Downloads
15
Maintainers
Readme
@meanie/mongoose-update-denormalized
A plugin for Mongoose to normalize JSON output
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