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

mongoose-moment

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-moment

Adds Moment storage support to Mongoose

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
942
increased by2.95%
Maintainers
1
Weekly downloads
 
Created
Source

mongoose-moment

Store Moment dates in Mongo using Mongoose internally as millisecond timestamps.

Installing

$ npm install mongoose moment mongoose-moment
var mongoose = require('mongoose')
require('mongoose-moment')(mongoose);

Configuration

Use the new SchemaType 'Moment' in your schema definitions:

var mySchema = new mongoose.Schema({
	created: 'Moment'
});
var MyModel = new mongoose.Model('MyModel', mySchema);

Usage

Writing models

var Moment = require('moment');
var myModel = new MyModel({ created: new Moment() });
myModel.save();

Reading models

var myModel = MyModel.findById('123', function(err, doc){
	console.log(doc.created.format());
});

Querying for models

Mongoose doesn't transform query values according to schemas, so you'll have to do it yourself. Internally, Moment values are stored in the database as the number of milliseconds since the Unix epoch. To find a document using a Moment field, use a query like

MyModel.find({ created: new Moment('2014-03-29').valueOf() }, function(err, docs) {});

Thanks

Keywords

FAQs

Package last updated on 05 Feb 2017

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