Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference nested object into other collection Mongodb

I want to reference nested object exist in another Collection object, in my Event object so that when i get Event of User than Venue of Event shall retrieve with it, i am new in mongodb and spring can any one help to do this.

class User{
private String name;
private Venue venue;

//Getter and Setter 
}

class Event {
@DBRef
private Venue venue;

//Getter and Setter 
}
like image 368
Qasim Khokhar Avatar asked Jan 12 '15 11:01

Qasim Khokhar


1 Answers

If each User has one Venue, you can reference User instead of Venue in Event. If a User may have more than one Venue, you better make Venues a seperate collection and reference both in User and Event.

like image 119
Mustafa Dokumacı Avatar answered Oct 20 '22 01:10

Mustafa Dokumacı