繁体   English   中英

从节点js更新多个mongoDB集合

[英]Updating multiple mongoDB collections from node js

我正在尝试使用mongoose和node.js更新mongoDB数据库中的两个单独的集合。 但是在发送标头后设置标题时出现错误。 这是错误

用于设置此代码的代码是: 码

170行是写入customer.update的行

您尝试在客户和管理员集合更新后两次发送响应。 这就是为什么您会收到此错误。

为了解决这个。 使用异步库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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM