Inserting a momentjs object in Meteor Collection

meteor, momentjs, mongodb

Solution

I strongly recommend storing dates as `Date` objects and using moment to format them after they are fetched. For example:

Posts.insert({message: 'hello', createdAt: new Date});

Then later when you want to display the date:

var date = Posts.findOne().createdAt;
moment(date).format('MMMM DD, YYYY');

Problem

I have a simple Meteor collection and I am trying to insert a document that has a momentjs property into it. So I do: ``` docId = Col.insert({m: moment()}); ``` However, when I try to get this document back with ``` doc = Col.findOne({_id: docId}) ``` I get "Invalid date" for doc.m like so: ``` Object {_id: "wnHzTpHHxMSyMxmu3", m: "Invalid date"} ``` Anyone?!

Original source