So basically, I have a requirement where I am trying to store a Class having 4 properties and the 5th property is a list in MongoDB, the catch is I want this list to have multiple object types. OR I want to know if I can save and retrieve below shown json structure in mongodb in the best way possible
I have tried using List type to store and fetch the Instruction list but it stores it incorrectly. Also have tried to serialize the Instruction list, It basically converts it into a single string.
[BsonId]
public int ID { get; set; }
[BsonElement]
public int ModuleID { get; set; }
[BsonElement]
public string ModuleName { get; set; }
[BsonElement]
public string Description { get; set; }
[BsonElement]
public string ModuleType { get; set; }
[BsonElement]
public List<object> Instruction { get; set; }
{
"moduleID": "24",
"moduleName": "Test Module",
"description": "Test Desc",
"moduleType": "Test Type",
"instruction": [{
"InstructionID": "1",
"Order": 1,
"InstructionName": "Test 1",
"Message": "Please select Deliver Type",
"HelpText": "This is delivery type module",
"PropertyType": "Test Prop",
"PropertyName": "TestPropName"
},
{
"InstructionID": "2",
"Order": 2,
"InstructionName": "Test 2",
"Message": "Select the supplier",
"HelpText": "This is supplier list",
"Filter": "",
"StartBy": "Test Date"
},
{
"InstructionID": "3",
"Order": 3,
"InstructionName": "Test 3",
"Message": "Select the Product",
"HelpText": "This is Product list",
"Filter": "SupplierList.SupplierID",
"Text": "Sample"
"StartBy": "Test Date"
"EndBy": "Test Date"
}
]
}
Am I missing something here? Is there a way to handle a list having multiple object types (maybe a ArrayList but that is similar to having a List).
In ideal scenario I would have a single instruction class which I will be passing in the root class but we have different instruction field being decided at runtime.
As you can see in the json the instruction array will have instructions with multiple different field, How should I handle this scenario?