【发布时间】:2015-07-24 03:22:59
【问题描述】:
在 Meteor 中将文档插入 MongoDB 集合时,不确定如何使用 $currentDate。
这只能用于更新而不是插入吗?看起来很奇怪,但我没有看到替代方案(除了使用 new Date 代替)。
示例
Stuff.insert({
owner: Meteor.userId(),
createdAt: ..., // how to create this field with $currentDate ?
theStuff: "Some of the good stuff"
})
笔记/想法/TL,DR
- 字段不能以 $ 运算符开头,或者,据我所知,大括号
{}。 - 如果确实如此,那么拥有一个只处理更新的运算符有什么意义?
- 为什么/什么时候
$currentDate比new Date好? - 如果使用 Moment.js esp,一件好事是 $currentDate 以 ISO 8601 格式输入。
- 答案是从一开始就做某种 upsert 吗?如果是这样,这会产生意想不到的后果吗?
【问题讨论】:
标签: javascript mongodb meteor mongodb-query