Hi I’m new to MongoDB and I have some basic needs giving me hard time.
I have the following data structure
public class Catalog
{
public string Id { get; set; }
public string Description { get; set; }
public string CountryCode { get; set; }
public List<Variant> Variants { get; set; } = new List<Variant>();
public class Variant
{
public string CatalogId { get; set; }
public string VariantId { get; set; }
public string Size { get; set; }
public string Color { get; set; }
public List<Price> Prices { get; set; } = new List<Price>();
}
public class Price
{
public string CatalogId { get; set; }
public string VariantId { get; set; }
public string PriceId { get; set; }
public double Price { get; set; }
public DateTime FromDate { get; set; }
public DateTime ToDate { get; set; }
}
}
I receive events containing partial information about one catalog reference when it is updated from the source of truth.
Example of bunch of Variants (without prices) received for one catalog ref:
public class VariantUpdateEvent
{
public List<VariantEvents> VariantEvents { get; set; } = new List<VariantEvents>();
public class VariantEvents
{
public string CatalogId { get; set; }
public string VariantId { get; set; }
public string Size { get; set; }
public string Color { get; set; }
}
}
And data :
[
{ "CatalogId" : "productA", "VariantId":"V123", "Size":"S", "Color":"Blue" },
{ "CatalogId" : "productA", "VariantId":"V456", "Size":"L", "Color":"Blue" },
{ "CatalogId" : "productA", "VariantId":"V789", "Size":"XL", "Color":"Red" }
]
Example of bunch of Prices (without variant) received for one catalog ref:
public class PriceUpdateEvent
{
public List<PriceEvents> PriceEvents { get; set; } = new List<PriceEvents>();
public class PriceEvents
{
public string CatalogId { get; set; }
public string VariantId { get; set; }
public string PriceId { get; set; }
public double Price { get; set; }
public DateTime FromDate { get; set; }
public DateTime ToDate { get; set; }
}
}
And data :
[
{ "CatalogId" : "productA", "VariantId":"V123", "PriceId":"P94457", "Price":100, "FromDate": "2021-10-01", "ToDate": "2021-10-25" },
{ "CatalogId" : "productA", "VariantId":"V123", "PriceId":"P86743", "Price":120, "FromDate": "2021-10-26", "ToDate": "2021-10-28" },
{ "CatalogId" : "productA", "VariantId":"V123", "PriceId":"P45468", "Price":90, "FromDate": "2021-10-29", "ToDate": "2021-12-31" },
{ "CatalogId" : "productA", "VariantId":"V456", "PriceId":"P4514256", "Price":10, "FromDate": "2021-10-01", "ToDate": "2021-10-02" },
{ "CatalogId" : "productA", "VariantId":"V456", "PriceId":"P4514654", "Price":20, "FromDate": "2021-10-03", "ToDate": "2021-10-28" },
]
Well how is it possible to :
-
Based on a VariantUpdateEvent : update only concerned variant part without overwriting nested prices (that we indeed don’t receive in such event)
-
Based on a PriceUpdateEvent : update only concerned prices
Is there any obvious solutions for these actions ?
Thank you !