public Class Team{
@Id
String id;
String name = "";
}
public Class Player{
@Id
String id;
String team_id = "";
String name = "";
}
Ho should i perform the "find" on the MongoDB for having a Team associated to the Player? I'm using the following:
Iterator<Player> plist = Player.findAllIter();
while (plist.hasNext()) {
Player p = plist.next();
Team t = p.getTeam();
}
Where in the class Player i have :
public static Iterator<Player> findAllIter() {
return players().find().as(Player.class).iterator();
}
public Team getTeam() {
Team t = Team.findById(this.team_id);
return t == null ? new Team() : t;
}
Is this correct? There is any better solution?