Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Step and Mongodb driver @ Nodejs

Step and Mongodb driver @ Nodejs

Problem

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 recieves an array of lenght 1, even though there are n filters. Any thoughts on what Im doing wrong? Or any suggestions on how to handle async code better?

Problem courtesy of: Peeter

Solution

Does this do the trick?

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

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Step and Mongodb driver @ Nodejs

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×