Document 1 : { options: [ { size: “s” }, { color: “red” } ]; }
Document 2 : { options: [ { size: “m” }, { color: “green” } ]; }
Result should be : { options: [ size:[“s”,“m”], { color:[“red”,“green”]} ]; }
Here,key object key name are dynamic that is they can be any other name like “fit”,“fabric” etc
You expected result is not valid JSON.
Could you confirm that what you want is in fact the following?
{ options : [ { size : [ "s" , "m" ] } , { color : [ "red" , "green" ] } ] }
But that does not seem intuitive. If I see your result documents I will assume I have the option size:s,color:green as valid choice. But it is not if you only have the 2 documents you shared.