My code looks like:
final Map<String, String> query = ["brochureId": brochureId, "recipientIdentifier": recipientIdentifier]
final List<WatcherNotificationMongoDb> watcherNotifications = WatcherNotificationMongoDb.findAll(query).toList()
if (!watcherNotifications){
return
}
for(final WatcherNotificationMongoDb notification : watcherNotifications) {
if (notification.dateViewed){
log.debug("...")
} else {
notification.dateViewed = new Date()
notification.viewType = viewType
if(!notification.save()) {
log.error("...")
}
}
}
I found that update works because document in database have dateViewed set to this same time when this errors occur.
I get this problem also on other collection and I can't reproduce it locally (the problem appear on production).