Fawn 介绍
Fawn提供了在mongoDB 数据库 上执行编辑的能力,作为一系列步骤。如果在任何步骤上发生 错误 ,则 数据库 将返回其初始状态(事务开始之前的状态)。它基于MongoDB文档中描述的两阶段提交系统。?
安装
npm install fawn
用法
var task = Fawn.Task();
//assuming "Accounts" is the Accounts collection
task.update("Accounts",{f irs tName: "John",lastName: "Smith"},{$inc: {balance: -20}})
.update("Accounts",{f irs tName: " bro ke",lastName: "Ass"},{$inc: {balance: 20}})
.run()
.then(function(results){
// task is complete
// result from f irs t operation
var f irs tUpdateResult = results[0];
// result from second operation
var secondUpdateResult = results[1];
})
.catch(function(err){
// Everything has been rolled back.
// log the error which caused the failure
console.log(err);
});
网站地址 : https://www.npmjs.com/package/fawn
GitHub: https://github.com/e-oj/Fawn
网站描述: 基于Promise的库,用于MongoDB中的事务
Fawn官方网站
官方网站: https://www.npmjs.com/package/fawn
如果觉得 网站内容还不错,欢迎将 网站 推荐给程序员好友。