action.datetimeExecuted = new Date().toISOString();
See line 84 there. What happens to createdAt from there... eventually it ends up as ISODate in Mongo, but I can't seem to do the same using a Sails model attribute.
I've already tried new Date().toISOString() as the defaultsTo for my attribute, and it didn't work there... The string has the right format, but it is still just a string datatype in mongo. I'll try setting it in beforeUpdate but I suspect the same thing will happen. Here is a text view result...
Thank you for the idea of using the lifecycle callback. Setting the value to new Date().toISOString() as your example does just inserted a string, but setting it to just new Date() worked! Seems odd to have to jump through the extra hoop of the lifecycle callback, so if anyone knows a better way, please let me know. Thanks!
Thanks again, I have a follow up question. This works great when I call (Collection).create from my conroller and set a parameter value to new Date(whatever).
But I can't get the defaultsTo parameter to work in the model.
"ValidationError": {
"start_date": [
{
"data": null,
"message": "Validation error: \"Invalid Date\" is not of type \"datetime\"",
"rule": "datetime"
}
],
"end_date": [
{
"data": null,
"message": "Validation error: \"Invalid Date\" is not of type \"datetime\"",
"rule": "datetime"
}
]
}This worked fine before setting schema to true.