I am writing a script in Nodejs to map a json to mongodb but I am really confused on how to tackle this as the structure is really complex. Any help would be appreciated! So basically the structure looks like this.
{
"4.1": {
"picture": "",
"code": {
"PEK": {
"number": 4.1,
"text": "XYZ."
},
"DXB": {
"number": 5.1,
"text": "XYZ"
},
"LAX": {
"number": 6.1,
"text": "XYZ"
},
"HND": {
"number": 6.1,
"text": "XYZ"
}
}
},
"4.2": {
"picture": "",
"province": {
"PEK": {
"number": 4.2,
"text": "XYZ"
},
"DXB": {
"number": 5.2,
"text": "XYZ"
},
"LAX": {
"number": 6.2,
"text": "XYZ"
},
"HND": {
"number": 6.2,
"text": "XYZ"
}
}
}
}
So I have put two instances for example just so it's easier to understand. What I want is that I am using the the number of "PEK" as a key to access the right object. When I get response from the server I get a number, and the code, for example 4.1 and DXB. Using this information I want to show DXB under 4.1 and also its respective image. All the objects under 4.1 are tied to a common image which is linked to 4.1 but they have their own respective number and text which I want to show at runtime depending on the response. What would be the smartest way to map this to mongodb. Any help would be appreciated, thanks!!