mongodb – Mongoose JS承诺?或者如何管理批量保存
栏目: JavaScript · 发布时间: 7年前
内容简介:翻译自:https://stackoverflow.com/questions/11913074/mongoose-js-promises-or-how-to-manage-batch-save
> How can I save multiple documents concurrently in Mongoose/Node.js?
有人提到使用像
q
这样的流量控制库,但是我也注意到 promises
在mongoose中,它可以用吗?我可以在jQuery Deferred / Promises中做
$.when(obj1.save(), obj2.save(), obj3.save()).then ->
# do something?
var functions = [];
for (var i=0; i < docs.length; i++) {
functions.push((function(doc) {
return function(callback) {
doc.save(callback);
};
})(docs[i]));
}
async.parallel(functions, function(err, results) {
console.log(err);
console.log(results);
});
翻译自:https://stackoverflow.com/questions/11913074/mongoose-js-promises-or-how-to-manage-batch-save
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 使用jQuery加载承诺
- Hortonworks收入增长40% 正努力兑现盈利承诺
- 腾讯支持GPL合作承诺 促进开源文化发展
- Angular 6.0 即将发布,承诺更小更快更易用
- 万豪国际承诺:如果发生欺诈行为将支付新护照的费用
- 谷歌移交 Kubernetes 管理权,并承诺资助 900 万美元
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Nature of Code
Daniel Shiffman / The Nature of Code / 2012-12-13 / GBP 19.95
How can we capture the unpredictable evolutionary and emergent properties of nature in software? How can understanding the mathematical principles behind our physical world help us to create digital w......一起来看看 《The Nature of Code》 这本书的介绍吧!