I have following add comment method:
public Comment addComment(Comment comment) {
if (StringUtils.isEmpty(comment.getId())) {
throw new IncorrectDaoOperation("Comment id is empty");
}
try {
commentCollection.insertOne(comment);
} catch (Exception e) {
throw new IncorrectDaoOperation(e.getMessage());
}
return comment;
}
and comment update:
public boolean updateComment(String commentId, String text, String email) {
try {
Document filter = new Document("_id", new ObjectId(commentId));
filter.put("email", email);
List<Comment> comments = new LinkedList<>();
commentCollection.find(filter).into(comments);
if (comments.size() == 1) {
Comment comment = comments.get(0);
comment.setText(text);
comment.setDate(Date.from(Instant.now()));
commentCollection.replaceOne(filter, comment);
return true;
}
} catch (Exception e) {
System.out.println("Error update for comment with id = " + commentId);
}
return false;
}
All tests from UpdateCreateCommentTest passed but mflix displays status “Create/Update Comments: Unable to update comment”. Whats wrong here?