在我的收藏中,我想自动生成createdAt
和updatedAt
字段,其中包含上次插入/更新对象的日期-就像在Ruby on Rails中发生的那样。目前,我正在与一位与此类似的观察员合作:
MyCollection.find({}).observeChanges({
changed: function(id, changes) {
MyCollection.update(id, ...);
},
});
有没有更好/更有效/更直接的方法?
我喜欢https://github.com/matb33/meteor-collection-hooks
collection.before.insert (userId, doc) ->
doc.createdAt = new Date().valueOf #toISOString()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句