There are two collections in a MongoDB database. One collection is called Department per the example below:
{
"_id": "Dept1",
"Description": "Department 1",
"ApplicationName": "Payroll",
"Version": 1
}
{
"_id": "Dept2",
"Description": "Department 2",
"ApplicationName": "Payroll",
"Version": 1
}
{
"_id": "Dept3",
"Description": "Department 3",
"ApplicationName": "Payroll",
"Version": 1
}
The other collection is called UserAssociation and its data looks like the following example:
{
"_id": "Associate1",
"DepartmentIds": ["Dept1","Dept2"]
}
{
"_id": "Associate2",
"DepartmentIds": ["Dept2","Dept3"]
}
{
"_id": "Associate3",
"DepartmentIds": ["Dept1", "Dept2","Dept3"]
}
The C# models of these two documents are:
public class Department
{
public string Id { get; set; }
public string Description { get; set; }
public string ApplicationName { get; set; }
public int Version { get; set; }
}
public class Associate
{
public string Id { get; set; }
public string[] DepartmentIds { get; set; }
}
I'd like to get the following model populated by aggregation or "join" (anything that can help better) at the end of the day:
public class DepartmentAssociation
{
public string AssociateId { get; set; }
public Department[] Departments { get; set; }
}
How can I achieve this goal in C#?