在我的收藏中,我想自动生成createdAtupdatedAt字段,其中将包含对象上次插入/更新的日期-就像在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()

关于javascript - meteor 中的自动createdAt和updatedAt字段,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22474667/

10-10 00:48