Mongodb 在 cron 作业中找到的集合抛出新错误('Can\'t wait without a fiber');

Mongodb colelction find in cron job throws new Error('Can\'t wait without a fiber');

我已经使用 npm 包 cron 设置了一个 cron 作业。我正在尝试执行以下 Coll.find().forEach 功能,但出现错误 Error: Can't wait without a fiber

    var job = new CronJob({
      cronTime: '00 09 11 * * 1-5',
      onTick: function() {
            var userIds = []

            Coll.find().forEach(function(doc) {
                    userIds.push(doc._id)
            });
      },
      start: false,
      timeZone: "Europe/London"
    });
   job.start();

我一直在使用 npm 包 fibers 和 future 库。我仍然遇到同样的错误。

var resultOne = collFind();


  function collFind() {
     var f = new future()
     var userIds = []

     Coll.find().forEach(function(doc) {
        userIds.push(doc.userId)
    });

    return f['return']({userIds:userIds}
    return f.wait()
  }

尝试使用 Meteor.bindEnvironment

var job = new CronJob({
  cronTime: '00 09 11 * * 1-5',
  onTick: Meteor.bindEnvironment(function() {
        var userIds = []

        Coll.find().forEach(function(doc) {
                userIds.push(doc._id)
        });
  }),
  start: false,
  timeZone: "Europe/London"
});
job.start();

它将确保回调get在当前纤程中运行,并确保所有全局变量都可访问。