I have the following problem. In this example dataset:
https://mongoplayground.net/p/itNnrDzZ4JQ
[
{
"name": "test",
"questions": [
{
"headline": "headline 1",
"answer": {
"@id": "001",
"m_IMG": {
"type": "06",
"img": {
"@id": "1111",
"shape": [
{
"@src": "/1_1.jpg",
"@type": "Z05"
},
{
"@src": "/1_2.jpg",
"@type": "Z08"
}
]
}
},
"text": "text1"
}
},
{
"headline": "Headline 2",
"answer": [
{
"@id": "001",
"m_IMG": {
"@type": "24",
"img": {
"@id": "1111",
"shape": {
"@src": "/2_1.jpg",
"@type": "Z05"
}
},
"text": "Test2"
}
},
{
"@id": "002",
"m_IMG": {
"@typeName": "",
"@type": "25",
"img": {
"@id": "2222",
"shape": [
{
"@src": "/2_1.jpg",
"@type": "Z05"
},
{
"@src": "2_2.jpg",
"@type": "Z08"
}
]
}
},
"text": "Test3"
}
]
}
]
}
]
You will find that if only a single answer to a question exists it is represented as an object. If more than one exists then it is an array. This is also true in the shape node. I wonder what is the best way to convert those nodes to be always arrays (so if one answer exists it would be an array of one element).