一切我可以找到一个撕心裂肺页面猫鼬结果说做这样的:如何从find方法返回Mongoose结果?
users.find({}, function(err, docs){
res.render('profile/profile', {
users: docs
});
});
我怎么能返回结果从查询,更喜欢这个?
var a_users = users.find({}); //non-working example
这样我就可以得到多个结果在页面上发布?
喜欢:
/* non working example */
var a_users = users.find({});
var a_articles = articles.find({});
res.render('profile/profile', {
users: a_users
, articles: a_articles
});
可以这样做?
当[ES7滚动](http://jakearchibald.com/2014/es7-async-functions/)时,你的梦想就会实现。 – royhowie 2015-06-13 04:23:15
你应该签出[deasync](https://www.npmjs.com/package/deasync),所以函数看起来像是同步执行的。 – 2015-07-25 21:24:01
为更好地理解这个问题和它的解决方案参考https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – devprashant 2017-06-02 16:49:10