使用限制
- session使用
仅支持通过以下接口获取session:
com.huawei.devspore.mas.mongo.core.client.Cluster.startSession() com.huawei.devspore.mas.mongo.core.client.Cluster.startSession(ClientSessionOptions clientSessionOptions) mongoTemplate.getMongoDbFactory().getSession(ClientSessionOptions.builder().build())
此session对应的Mongo数据源为当前active数据源。所以在使用session相关的操作时,请务必保证所有操作都能路由到active数据源。
SessionScoped sessionScoped = mongoTemplate.withSession(ClientSessionOptions.builder().build()); sessionScoped.execute(action -> { action.insert(xxx); // 写操作,路由到active数据源 action.count(xxx); // 读操作,路由到本地数据源 });
2. 有限制的命令
命令名称 |
使用限制 |
原因 |
---|---|---|
MongoTemplate.findAllAndRemove() |
本地读单边写模式下,此命令不支持 |
原生mongo没有此命令,是spring-data-mongo对find和remove操作的封装 |