rodzodgt
rodzodgt

Reputation: 13

How to save createdAt updatedAt as Date type instead of String type with Sailsjs 1.0 and mongodb

Sails 1.x saves createdAt and updatedAt as string instead of Date type with mongodb.

the problem is that i have aggregation pipes with $add (adding days, months, secs, etc...) with the createdAt and updatedAt fields and Mongodb throws error that $add only accept type of numeric or date, not string.

Thank You

Upvotes: 1

Views: 825

Answers (1)

nopuck4you
nopuck4you

Reputation: 1700

Make sure your model definition for the date colum uses type 'ref' and columnType 'datetime':

date: { type: 'ref', columnType: 'datetime', required: true },
number: { type: 'number', columnType: 'float', defaultsTo: 0 }

Upvotes: 2

Related Questions