Spring Data MongoDB 4.0 transactions support

旧巷老猫 提交于 2019-12-19 11:49:15

问题


MongoDB 4.0 are going to introduce transactions support with ACID guarantees.

Does Spring Data MongoDB already supports the transactions in MongoDB and if no, when this awesome feature will be available. I really need it, taking into account the following issue - MongoDB schema design in order to support application horizontal scaling


回答1:


Does Spring Data MongoDB already supports the transactions in MongoDB

Spring Data Lovelace M3 (2.1.0.M3) supports synchronous transaction for MongoDB v4.0, released on May 17th 2018. See also Spring Data Lovelace M3 release notes.

Example from Spring Data docs: MongoDB transactions

ClientSession session = client.startSession(options);                   

template.withSession(session)
    .execute(action -> {
        session.startTransaction();                                     
        try {

            Step step = // ...;
            action.insert(step);
            process(step);
            action.update(Step.class).apply(Update.set("state", // ...
            session.commitTransaction();                                
        } catch (RuntimeException e) {
            session.abortTransaction();                                 
        }
    }, ClientSession::close)                                            
    .subscribe();

See also related: DATAMONGO-1920 and DATAMONGO-1970



来源:https://stackoverflow.com/questions/50845025/spring-data-mongodb-4-0-transactions-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!