小编lak*_*yap的帖子

如何在forEach循环中运行mongoose查询

任何人都可以帮助我如何在nodejs中的forEach循环中运行mongoose查询并建议两个集合的内部联接结果需要

如下细节

userSchema.find({}, function(err, users) {
    if (err) throw err;
    users.forEach(function(u,i){
        var users = [];
        jobSchema.find({u_sno:s.u.sno}, function(err, j) {
            if (err) throw err;
            if (!u) {
                res.end(JSON.stringify({
                    status: 'failed:Auction not found.',
                    error_code: '404'
                }));
                console.log("User not found.");
                return 
            }
            users.push(j);
        })
    })
    res.send(JSON.stringify({status:"success",message:"successfully done",data:{jobs:j,users:u}}));
})
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js express

6
推荐指数
3
解决办法
2万
查看次数

标签 统计

express ×1

mongodb ×1

mongoose ×1

node.js ×1