带有本地托管数据库的cursor.toArray()的未定义函数错误

时间:2015-08-24 14:43:31

标签: node.js mongodb mongoose local-database

我收到错误:

" TypeError:undefined不是函数" ..for toArray()在下面的代码中。

// Require mongo db user model
var User = require("./models/user.js"); 

.
.
.

// list of members page ====================================================
// protected page
app.get("/members", isLoggedIn, function(req, res) {

    // get array list of usernames
    var pttCursor = User.find( { } , { firstname: 1, lastname: 1, _id: 0 } );
    var membersArray = pttCursor.toArray(function(err, docs){});

    res.render("members.ejs", {
        user : req.user, // get user out of session and pass to template
        members : membersArray
    });
});

我希望/ members页面可以访问一组用户名。

编辑:我也试过" cursor.map()" ..我得到同样的错误

// get array list of usernames
var pttCursor = User.find( { } , { firstname: 1, lastname: 1, _id: 0 } );
var membersArray = pttCursor.map(function(pttDoc){
    return pttDoc.firstname + pttDoc.lastname;
});

0 个答案:

没有答案