
# 使用限制
- 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数据源。
  在本地读单边写模式下，如下使用方式会抛出异常：java.lang.IllegalStateException: state should be: ClientSession from same MongoClient
  ```
  SessionScoped sessionScoped = mongoTemplate.withSession(ClientSessionOptions.builder().build());
  sessionScoped.execute(action -> {    
      action.insert(xxx); // 写操作，路由到active数据源
      action.count(xxx);  // 读操作，路由到本地数据源
  });
  ```
  
- 2. 有限制的命令
  表1MAS-Mongo-SDK有限制的命令 
  | 命令名称                             | 使用限制              | 原因                                                |
  |:---|:---|:---|
  | MongoTemplate.findAllAndRemove() | 本地读单边写模式下，此命令不支持。 | 原生mongo没有此命令，是spring-data-mongo对find和remove操作的封装。 |
     
  
 
