
336
|
第
20
章
function updateEmployeeInfo(session) {
employeesCollection = session.getDatabase("hr").employees;
eventsCollection = session.getDatabase("reporting").events;
session.startTransaction( {writeConcern: { w: "majority" } } );
try{
employeesCollection.updateOne( { employee: 3 },
{ $set: { status: "Inactive" } } );
eventsCollection.insertOne( { employee: 3, status: { new: "Inactive",
old: "Active" } } );
} catch (error) {
print("Caught exception during transaction, aborting.");
session.abortTransaction();
throw error;
}
commitWithRetry(session);
}
20.5
MongoDB
不能保证什么
MongoDB
在一些情况(比如存在硬件问题或文件系统错误)下无法保证持久性。特别是,
如果硬盘损坏,则
MongoDB ...