diff --git a/src/main/java/com/devsuperior/workshopmongo/config/SeedingDatabase.java b/src/main/java/com/devsuperior/workshopmongo/config/SeedingDatabase.java index 2377827..69a8845 100644 --- a/src/main/java/com/devsuperior/workshopmongo/config/SeedingDatabase.java +++ b/src/main/java/com/devsuperior/workshopmongo/config/SeedingDatabase.java @@ -38,11 +38,7 @@ public void run(String... args) throws Exception { User bob = new User(null, "Bob Grey", "bob@gmail.com"); Flux insertUsers = userRepository.saveAll(Arrays.asList(maria, alex, bob)); - insertUsers.subscribe(); - - maria = userRepository.searchEmail("maria@gmail.com").block(); - alex = userRepository.searchEmail("alex@gmail.com").block(); - bob = userRepository.searchEmail("bob@gmail.com").block(); + insertUsers.subscribe(); Post post1 = new Post(null, Instant.parse("2022-11-21T18:35:24.00Z"), "Partiu viagem", "Vou viajar para São Paulo. Abraços!", maria.getId(), maria.getName()); @@ -62,7 +58,7 @@ public void run(String... args) throws Exception { Mono deleteUser = userRepository.delete(maria); deleteUser.subscribe(); - + Mono insertSingleUser = userRepository.save(maria); insertSingleUser.subscribe(); } diff --git a/src/main/java/com/devsuperior/workshopmongo/entities/User.java b/src/main/java/com/devsuperior/workshopmongo/entities/User.java index 365a758..158648f 100644 --- a/src/main/java/com/devsuperior/workshopmongo/entities/User.java +++ b/src/main/java/com/devsuperior/workshopmongo/entities/User.java @@ -6,6 +6,7 @@ import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; +import org.springframework.data.mongodb.core.mapping.DocumentReference; @Document(collection = "user") public class User { @@ -15,6 +16,7 @@ public class User { private String name; private String email; + @DocumentReference(lazy = true) private List posts; public User() {