I want to set the WriteConcern in spring mongodb to acknowledged. Also, I'm wondering if this is the default value? I am using the spring.data.mongodb.uri in my application.properties so I don't have any mongo configuration class.
From the docs of SpringData here
9.4.3. WriteConcern You can set the com.mongodb.WriteConcern property that the MongoTemplate will use for write operations if it has not yet been specified via the driver at a higher level such as com.mongodb.Mongo. If MongoTemplate’s WriteConcern property is not set it will default to the one set in the MongoDB driver’s DB or Collection setting.
9.4.4. WriteConcernResolver For more advanced cases where you want to set different WriteConcern values on a per-operation basis (for remove, update, insert and save operations), a strategy interface called WriteConcernResolver can be configured on MongoTemplate. Since MongoTemplate is used to persist POJOs, the WriteConcernResolver lets you create a policy that can map a specific POJO class to a WriteConcern value. The WriteConcernResolver interface is shown below.
public interface WriteConcernResolver {
WriteConcern resolve(MongoAction action);
}
Find a direct implementation here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With