Javascript 挂钩前收集的Meteor setTimeout

Javascript 挂钩前收集的Meteor setTimeout,javascript,meteor,Javascript,Meteor,仅当myCollection在2分钟后未填充类别属性时,此Meteor服务器代码才需要发送电子邮件 但不管怎样,它每次都会发送电子邮件。是否有任何建议,使其仅在2分钟后类别仍然为空时发送电子邮件?thx let myFunc = function (){ myCollection.inert({lastName: 'john'}); //run other code to populate the myCollection.category } myCollection.before.

仅当myCollection在2分钟后未填充
类别
属性时,此Meteor服务器代码才需要发送电子邮件

但不管怎样,它每次都会发送电子邮件。是否有任何建议,使其仅在2分钟后
类别仍然为空时发送电子邮件?thx

let myFunc = function (){
  myCollection.inert({lastName: 'john'});
  //run other code to populate the myCollection.category
}

myCollection.before.insert(function (userId, doc) {
  if (userId === '8mmjdueej') {
     lib.alertAdmin(doc);
   }
});

   'alertAdmin': function (Obj) {
      Meteor.setTimeout(function () {
          let category = myCollection.find({lastName: Obj.name}).bigCategory;
          if (!category) {
            lib.sendEmail(null, 'failed to get category for: ' + Obj.name);
          }
        },
        120000);
    },
这可能是问题所在。
find
返回Mongo的光标,而不是文档本身。您可以为此使用
findOne

let category = myCollection.find({lastName: Obj.name}).bigCategory;