![](/img/trans.png)
[英]how to render multiple collections data to page in node js from mongodb
[英]Updating multiple mongoDB collections from node js
您尝试在客户和管理员集合更新后两次发送响应。 这就是为什么您会收到此错误。
为了解决这个。 使用异步库http://caolan.github.io/async/docs.html#.parallel
或带有回调的自定义函数,并且仅在所有集合更新后才发送标头。
这是例子
async.parallel([
adminName: function(callback) {
admin.update({yourUpdateCode}, function(err, AdminDoc){
//you may want to add error handling here
callback(null, AdminDoc);
});
},
customerName: function(callback) {
customer.update({yourUpdateCode}, function(err,doc){
//you may want to add error handling here
callback(null, CustDoc);
});
}],
function(err, results) {
// results is now equals to: {adminName: AdminDoc, customerName: CustDoc}
//your final callback here.
});
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.