Spring Bidirectional dbref Mongodb

Is it possible to have bidirectional dbref in mongodb (like what we can have in a relational database, a one-to-many bidirectional relationship). If possible, this can be represented in Mongodb, as well as using Spring -mongodb. The exact scenario I come across is below

Say we would like to create a forum. A forum can have several forums. Each topic can be posted, but the message should be marked with one forum topic. There is one-to-many relationships between forums -> threads and Topic -> posts, there is also a connection with posts -> forum threads. Given the situation, how can this be solved with Spring-Mongodb.

+6
source share
1 answer

Mongodb does not support bidirectional dbref, primarily as you kow. it is a document-based data repository using key-value pairs to store each information. If you want to save the forum data inside mongodb, you must follow this specific Structure document

public class Forum { @Id private String forunId; private String forumTitle; private String description; private Date createdDate; @DBRef private List<Topic> topics } public class Topic { @Id private String topicId; private String topicName; @DBRef private List<Post> posts } public class Post { @Id private String postId; private String comment; } 

Requested request

0
source

Source: https://habr.com/ru/post/986049/


All Articles