【问题标题】:Issue using step (control flow library) and mongoose使用步骤(控制流库)和猫鼬的问题
【发布时间】:2012-05-10 14:10:48
【问题描述】:

如果我以正常方式查询集合中的所有文档,我没有问题:https://gist.github.com/2562954。这个的输出是

found docs []

但是,如果我引入 Step (https://github.com/creationix/step),那么输出的不是文档数组:https://gist.github.com/2562852。这个的输出是:

found docs { options: { populate: {} },
  safe: undefined,
  _conditions: {},
  op: 'find',
  model: [Function: Model] }

这到底是怎么回事?我真的很想在 mongoose 中使用控制流库,但这让我抓狂!

【问题讨论】:

    标签: node.js mongoose control-flow


    【解决方案1】:

    试试这个。我有一个类似的 Step 函数在工作。

    注意:我不知道这是否是导致问题的原因,但是当您在 coffeescript 中执行此操作时,它会在 models.Foobar.find({}).run(this); 之前添加“return”

    step(
      function getFoobar() {
        models.Foobar.find({}).run(this);
      }, function (err, docs) {
        console.log('found docs', docs);
        console.log('disconnecting');
        return mongoose.disconnect(this);
      }, function (err) {
        if (err) {
            throw err;
        }
        return console.log('disconnected');
    });
    

    【讨论】:

      猜你喜欢
      • 2017-09-26
      • 2014-11-19
      • 2020-10-16
      • 2015-05-05
      • 2020-03-07
      • 2017-02-17
      • 2013-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多