Suppose I have to simple objects stored in mongoDB with many-to-many relationship:
public class Person {
public Guid Id {get; set;}
public string Name {get; set;}
public List<Guid> Groups {get; set;}
}
public class Group {
public Guid Id {get; set;}
public string Title {get; set;}
public List<Guid> Persons {get; set;}
}
So, any person might belong to a number of groups while any group consists of number of persons. I'm trying to find the most efficient way to retrieve persons (or groups) data using .NET driver and, if possible, avoid to run multiple queries for this purpose:
Processing "get person by Id" request I expect to have a data described as following:
PersonModel: {
Id: <Guid>,
Name: <string>,
Groups: [
{ Id: <Guid>, Title: <string> },
{ Id: <Guid>, Title: <string> },
...
]
}
and the result of "get group by Id" request is expected to be as following:
GroupModel: {
Id: <Guid>,
Title: <string>,
Persons: [
{ Id: <Guid>, Name: <string> },
{ Id: <Guid>, Name: <string> },
...
]
}
Any suggestions will be very appreciated. Thanks