I have two collections Product and Categories. A product can have multiple categories. Product is have a string array for keep category ids (as name Product.Categories).
I want to select products with category details. Note: I'm using MongoDB .Net Driver. Can I do this with Linq query?
Products Collection: `
{
_id : "product_1",
title : "Product Title 1",
categories : ["category_1", "category_2"]
},
{
_id : "product_2",
title : "Product Title 2",
categories : ["category_2"]
}
Categories Collection:
{
_id: "category_1",
name : "Category 1 Name",
},
{
_id: "category_2",
name : "Category 2 Name",
}
I want to result like below:
{
_id : "product_1",
title :"Product Title 1",
categories : [
{_id = "category_1", name="Category 1 Name"},
{_id = "category_2", name="Category 2 Name"},
]
},
{
_id : "product_2",
title :"Product Title 2",
categories : [
{_id = "category_2", name="Category 2 Name"},
]
}