Not sure how to use $currentDate when inserting a document into a MongoDB collection in Meteor.
Can this only be used in an update, not an insert? Would seem strange, but I don't see an alternative (other than using new Date
instead).
Example
Stuff.insert({
owner: Meteor.userId(),
createdAt: ..., // how to create this field with $currentDate ?
theStuff: "Some of the good stuff"
})
Notes / Thoughts / TL,DR
- Fields can't start with $ operators or, as far as I know, curly braces
{}
. - What's the point of having an operator that only works with updates, if that's indeed the case?
- Why/when is
$currentDate
better thannew Date
? - One nice thing, if using Moment.js esp, is that $currentDate is entered in ISO 8601 format.
- Is the answer to do some kind of upsert from the start? If so, could this have unintended consequences?