mongoose-timezone
v1.3.0
Published
[![Build Status](https://travis-ci.org/rodrigogs/mongoose-timezone.svg?branch=master)](https://travis-ci.org/rodrigogs/mongoose-timezone) [![Code Climate](https://codeclimate.com/github/rodrigogs/mongoose-timezone/badges/gpa.svg)](https://codeclimate.com/
Downloads
1,260
Readme
mongoose-timezone
A mongoose plugin to normalize stored dates timezone. By default mongo dates are stored in UTC format, this behaviour may cause problems when using advanced aggregation queries or when retrieving those dates from another system with different timezone.
mongoose-timezone basically adds the current timezone offset to the date before store and removes the offset when retrieving data. This way dates are kept proportional in the database and in the app.
Install
npm install mongoose-timezone --save
Usage
const mongoose = require('mongoose');
const timeZone = require('mongoose-timezone');
const Schema = new mongoose.Schema({
date: Date,
subDocument: {
subDate: {
type: Date,
},
},
});
// If no path is given, all date fields will be applied
Schema.plugin(timeZone, { paths: ['date', 'subDocument.subDate'] });
mongoose.model('Schema', Schema);
Notes
- insertMany function is not supported due to mongoose's API limitations
- update function is not supported due to mongoose's API limitations, save function could be used instead.
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -m 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
License
Licence © Rodrigo Gomes da Silva