I verified that there are no triggers or change streams enabled on the database. Additionally, I’ve added more logging statements to the code for better tracking.
Here’s the updated code snippet:
`
@Override
public void handle(DeviceDTO deviceDTO) {
var device = deviceService.getByDeviceId(deviceDTO.getDeviceId());
var deviceData = deviceDTO.bindDataToClass(DeviceRenameData.class);
var newName = deviceData.getName();
var deviceInfo = device.getDeviceInfo();
deviceInfo.setDeviceName(newName);
device.setDeviceInfo(deviceInfo);
log.info(“Setting the name of device to {}”, newName);
deviceRepository.save(device);
var savedDevice = deviceRepository.findByDeviceId(device.getDeviceId())
.orElseThrow(() → new RuntimeException(“Device not found”));
log.info(“Logging the name after changing: {}”, savedDevice.getDeviceInfo().getDeviceName());
}
`
Server Log:
2024-08-02T13:48:30.263+05:45 INFO 3000 --- [boundChannel-10] c.s.m.d.user.DeviceRenameACKHandler : Setting the name of device to BEATRIX 2024-08-02T13:48:30.278+05:45 INFO 3000 --- [boundChannel-10] c.s.m.d.user.DeviceRenameACKHandler : Logging the name after changing: BEATRIX
The update persists in the database inconsistently. It works on my local machine with MongoDB, but not consistently on the production environment.