sql >> Base de Datos >  >> NoSQL >> MongoDB

Morphia/MongoDB:Acceder al objeto incrustado desde un objeto @Embedded

Dado que ya tiene el objeto de entrada de blog, ¿por qué no usar un bucle Java simple para filtrarlo?

@Entity
class BlogEntry {

    @Embedded
    List<BlogComment> comments

    public BlogComment findCommentByAuthorId(String authorId) {
        if (null == authorId) return null;
        for (BlogComment comment: blogEntry.comments) {
           if (authorId.equals(comment.authorId) return comment;
        }
        return null;
    }

}