【问题标题】:Step and Mongodb driver @ NodejsStep 和 Mongodb 驱动@Nodejs
【发布时间】:2012-05-10 20:00:02
【问题描述】:
Step(
                function findFilters() {
                    database.connection.collection("diary_filter").find(this);
                },
                function loopFilters(error, cursor) {
                    var group = this.group();
                    cursor.each(group());
                },
                function testFilters(err, filters) { 
                    console.log("here we are", filters.length);
                }
            );

testFilters 接收长度为 1 的数组,即使有 n 个过滤器。关于我做错了什么有什么想法吗?或者关于如何更好地处理异步代码的任何建议?

【问题讨论】:

    标签: node.js mongodb


    【解决方案1】:

    这能解决问题吗?

    Step(
        function findFilters() {
            database.connection.collection("diary_filter").find().toArray(this);
        },
        function testFilters(err, filters) { 
            console.log("here we are", filters.length);
        }
    );
    

    【讨论】:

      【解决方案2】:

      这永远不会起作用,因为 step 无法正确交互,并且不应该以这种方式使用。

      不使用 step 和 toArray 重写它,因为无论如何你都要撤回所有项目

      database.connection.collection("diary_filter").find().toArray(function(err, items) {});
      

      【讨论】:

      • -1。 “这永远不会起作用,因为 step 无法正确交互,也不应该以这种方式使用。” 这甚至不连贯。 @Peeter 在此处使用 Step 没有任何固有错误;也许还有更多代码省略,需要在之后继续。即使您在此处的示例也可以集成到 Step 中,尽管您声称它“永远不会工作”。
      猜你喜欢
      • 2014-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-03
      • 2021-06-05
      • 1970-01-01
      • 1970-01-01
      • 2013-12-30
      相关资源
      最近更新 更多