Announcement Announcement Module
Collapse
No announcement yet.
Inserting Embedded document data Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inserting Embedded document data

    I am new to spring-data and just trying to understand the best way to get things done. Assume I have a collection called Artist, and with in I have a list of Albums, something like this:

    @Document
    public class Artist {
    @Id
    String artistId;
    String name;
    List<Album> albums;
    }

    if I want to add an album to this artist what is the best way to do this? Should I first find the artist, add to the list and then save the artist?

    Artist a=artistRepo.findByName("thename");
    a.getAlbums().add(new Album());
    artistRepo.save(a);

    or is there a more efficient way to do this?

    Thanks.
Working...
X