Java – many to many in mongodb configured with spring (comments first)
                                        
                    •
                    Java                                    
                I'm modeling a pattern Since I am a novice of Mongo dB, I don't know how to model NoSQL database
Using spring data is really in the list Above, @ dbref is used to support one to many But many people are what I want
Any help will be greatly appreciated Please prefer to use code to explain Or demonstrate the structure Thank you in advance
Solution
There are several ways to implement many - to - many in mongodb
I think the simplest is:
Many to many relationship scenario:
After de Standardization:
Your spring data code looks like this:
public class Category {
    @Id
    private ObjectId id;
    private String category_name;
    @DbRef
    private List<Product> products_ids;
    // ... getters and setters ...
}
public class Product {
    @Id
    private ObjectId id;
    private String product_name;
    @DbRef
    private List<Category> categories_ids;
    // ... getters and setters ...
}
                
                            The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
                        
                                            
                        THE END
                    
                    
                    
                                                        二维码
                        
                        
                                                
                        