简体   繁体   English

mongo-scala驱动程序交易示例

[英]Example of mongo-scala-driver transaction

Mongodb 4 added multi document transaction support. Mongodb 4添加了多文档事务支持。

Mongo-scala-driver ( http://mongodb.github.io/mongo-scala-driver/2.4/ ) supports mongodb 4, but I cannot find any example how to use transaction with scala. Mongo-scala-driver( http://mongodb.github.io/mongo-scala-driver/2.4/ )支持mongodb 4,但我找不到如何在scala中使用事务的示例。

Can anybody provide the link or code snippet? 有人可以提供链接或代码段吗?

PS: There is synchronous transaction example in the official mongodb site, but I need example of async, non-blocking transaction in scala . PS:在mongodb官方站点上有同步事务示例,但是我需要在scala中进行异步,非阻塞事务的示例。

There is an example in the transaction and drivers documentation under the Scala tab. 事务和驱动程序文档的Scala选项卡下有一个示例。

There are a few extra caveats / gotchas for scala that are covered in the example code . 示例代码涵盖了一些额外的Scala注意事项/注意事项。

  • Each observable within the transaction must be passed the ClientSession 事务中的每个可观察对象都必须传递ClientSession
  • Each observable must be subscribed to in order for anything to happen (they are cold observables). 必须订阅每个可观察对象,以便发生任何事情(它们是冷可观察对象)。
  • Transactions can be retried, if they meet the criteria. 如果符合条件,则可以重试交易。 An example is provided in the code. 代码中提供了一个示例。

There is no Observable abstraction as of version 2.4.0 but there are plans to simplify the API in the future. 从2.4.0版开始,没有可观察的抽象,但是将来有计划简化API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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