package com.chushang.common.mongo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.MongoTransactionManager;

/**
 * @author by zhaowenyuan create 2022/7/18 14:34
 */
public class MongoTransaction {
    /**
     * 配置 Mongo 事务管理
     * 需要 mongo 数据库开启 副本
     * 单机情况下, 事务无效
     */
    @Bean
    public MongoTransactionManager transactionManager(MongoDatabaseFactory mongoDatabaseFactory){
        return new MongoTransactionManager(mongoDatabaseFactory);
    }
}
