Skip to content

Commit

Permalink
add @DocumentReference in posts of user
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveiralex committed Nov 17, 2022
1 parent 374cbc2 commit e7450af
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ public void run(String... args) throws Exception {
User bob = new User(null, "Bob Grey", "[email protected]");

Flux<User> insertUsers = userRepository.saveAll(Arrays.asList(maria, alex, bob));
insertUsers.subscribe();

maria = userRepository.searchEmail("[email protected]").block();
alex = userRepository.searchEmail("[email protected]").block();
bob = userRepository.searchEmail("[email protected]").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());
Expand All @@ -62,7 +58,7 @@ public void run(String... args) throws Exception {

Mono<Void> deleteUser = userRepository.delete(maria);
deleteUser.subscribe();

Mono<User> insertSingleUser = userRepository.save(maria);
insertSingleUser.subscribe();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -15,6 +16,7 @@ public class User {
private String name;
private String email;

@DocumentReference(lazy = true)
private List<Post> posts;

public User() {
Expand Down

0 comments on commit e7450af

Please sign in to comment.