Spring Data MongoDB 4.0 transactions support

2019-03-03 23:42发布

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条回答
劳资没心,怎么记你
2楼-- · 2019-03-04 00:16

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

查看更多
登录 后发表回答