MongoDB交易 [英] MongoDB transaction
本文介绍了MongoDB交易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#中有如下方法:
I have a method like below in C#:
private void Save(object)
{
mongoCollection.Save(object);
someotherRelationaldb.Save(object);
}
我有两个DB,我必须在其中保存一个对象.一个是MongoDB,另一个是关系数据库SQL服务器.如果在关系数据库上提交失败,我想回滚MongoDB保存(我想保持保存顺序).使用C#驱动程序进行回滚的正确方法是什么?
I have two DBs in which I have to save a object. One is MongoDB and another is a relational DB SQL server. If the Commit on Relational DB fails, I want to rollback the MongoDB save (I would like to maintain the order of save). What would be the proper way to rollback using the C# driver.
推荐答案
是
现在可以.
例如Java;
try (ClientSession clientSession = client.startSession()) {
clientSession.startTransaction();
collection.insertOne(clientSession, docOne);
collection.insertOne(clientSession, docTwo);
clientSession.commitTransaction();
}
这篇关于MongoDB交易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文