In my C# code, I have an enum type that is going to be stored in MongoDB as string. In my C# code I have this type:
public enum Color
{
Unknown =0,
Red =1,
Blue =2,
Brown =3,
}
When in MongoDB string value is Red, Blue or Brown there is no problem but sometimes in DB there are other colours that are not included in my enum type like black, in this case, I expect the Color deserialized to Unknown but I get deserializing error indicates that black is not defined. Is there any way to handle this? I can not add every colour on my side and I can not change the enum type to any other type. I'm wondering how can I deserialize it to Unknown?