0

如题,在springboot中,配置mongoTemplate的writeconcern参数不起作用。使用已经把secondary用fsyncLock()锁住,在primary上用指令插入数据,w=2时会出现waiting for replication timed out提示,配置方法代码如下:

// Version 1: set statically
// mongoTemplate.setWriteConcern(WriteConcern.MAJORITY);
// Version 2: provide a WriteConcernResolver, which is called for _every_ MongoAction
// which might degrade performance slightly (not texted)
// and is very flexible to determine the value
// mongoTemplate.setWriteConcernResolver(action-> WriteConcern.W3);
// Version 3:
// mongoTemplate.setWriteConcernResolver(new MyWriteConcernResolver());
mongoTemplate.setWriteResultChecking(WriteResultChecking.EXCEPTION);

非常感谢

未选择答案

补充一下配置方法:
@Bean
public MongoTemplate mongoTemplate(MongoDatabaseFactory factory, MongoConverter converter){
MongoTemplate mongoTemplate = new MongoTemplate(factory, converter);
log.warn(“Bean mongoTemplate”);
// Version 1: set statically
// mongoTemplate.setWriteConcern(WriteConcern.MAJORITY);
// Version 2: provide a WriteConcernResolver, which is called for _every_ MongoAction
// which might degrade performance slightly (not texted)
// and is very flexible to determine the value
// mongoTemplate.setWriteConcernResolver(action-> WriteConcern.W3);
// Version 3:
// mongoTemplate.setWriteConcernResolver(new MyWriteConcernResolver());
mongoTemplate.setWriteResultChecking(WriteResultChecking.EXCEPTION);
return mongoTemplate;
}