In Spring Boot I want to update a field in collection using other field from that collection.
I tried this, but it doesn't work.
public void setTypeOfPayment(MongoTemplate mongoTemplate) {
Query query = new Query();
Criteria paymentTypeFilter1 = Criteria.where("payment_type").is("SOME1");
Criteria paymentTypeFilter2 = Criteria.where("payment_type").is("SOME2");
query.addCriteria(paymentTypeFilter1.orOperator(paymentTypeFilter2));
Update update = new Update();
update.set("payment.type_of_payment", "$payment_type");
mongoTemplate.updateMulti(query, update, Report.class);
}
I want to put existing payment_type value into payment.type_of_payment but I only get string $payment_type.
Is there a way to achieve this?
Update: my MongoDb version is 4.0.6.