Untitled
unknown
json
a year ago
7.1 kB
5
Indexable
// Define a lookup table var countryCodeLookup = { "202": "Afghanistan", "276": "Albania", "603": "Algeria", "544": "American Samoa", "213": "Andorra", "631": "Angola", "365": "Anguilla", "344": "Antigua and Barbuda", "722": "Argentina", "283": "Armenia", "363": "Aruba", "505": "Australia", "232": "Austria", "400": "Azerbaijan", "364": "Bahamas", "426": "Bahrain", "470": "Bangladesh", "342": "Barbados", "257": "Belarus", "206": "Belgium", "702": "Belize", "616": "Benin", "350": "Bermuda", "402": "Bhutan", "736": "Bolivia", "362": "Bonaire, Sint Eustatius and Saba", "218": "Bosnia and Herzegovina", "652": "Botswana", "724": "Brazil", "528": "Brunei Darussalam", "284": "Bulgaria", "613": "Burkina Faso", "642": "Burundi", "456": "Cambodia", "624": "Cameroon", "302": "Canada", "625": "Cape Verde", "346": "Cayman Islands", "623": "Central African Republic", "622": "Chad", "730": "Chile", "460": "China", "732": "Colombia", "654": "Comoros", "629": "Congo", "548": "Cook Islands", "712": "Costa Rica", "612": "Côte d'Ivoire", "219": "Croatia", "368": "Cuba", "280": "Cyprus", "230": "Czech Republic", "630": "Democratic Republic of the Congo", "238": "Denmark", "638": "Djibouti", "366": "Dominica", "370": "Dominican Republic", "740": "Ecuador", "602": "Egypt", "706": "El Salvador", "627": "Equatorial Guinea", "657": "Eritrea", "248": "Estonia", "636": "Ethiopia", "288": "Faroe Islands", "542": "Fiji", "244": "Finland", "208": "France", "340": "French Guiana", "547": "French Polynesia", "628": "Gabon", "607": "Gambia", "282": "Georgia", "262": "Germany", "620": "Ghana", "266": "Gibraltar", "202": "Greece", "290": "Greenland", "352": "Grenada", "340": "Guadeloupe", "535": "Guam", "704": "Guatemala", "611": "Guinea", "632": "Guinea-Bissau", "738": "Guyana", "372": "Haiti", "708": "Honduras", "454": "Hong Kong", "216": "Hungary", "274": "Iceland", "404": "India", "510": "Indonesia", "432": "Iran", "418": "Iraq", "272": "Ireland", "425": "Israel", "222": "Italy", "338": "Jamaica", "440": "Japan", "416": "Jordan", "401": "Kazakhstan", "639": "Kenya", "545": "Kiribati", "467": "Kuwait", "437": "Kyrgyzstan", "457": "Laos", "247": "Latvia", "415": "Lebanon", "651": "Lesotho", "618": "Liberia", "606": "Libya", "295": "Liechtenstein", "246": "Lithuania", "270": "Luxembourg", "455": "Macau", "294": "Macedonia", "646": "Madagascar", "650": "Malawi", "502": "Malaysia", "472": "Maldives", "610": "Mali", "278": "Malta", "551": "Marshall Islands", "340": "Martinique", "609": "Mauritania", "617": "Mauritius", "334": "Mayotte", "334": "Mexico", "537": "Micronesia", "259": "Moldova", "212": "Monaco", "428": "Mongolia", "297": "Montenegro", "354": "Montserrat", "604": "Morocco", "643": "Mozambique", "414": "Myanmar", "649": "Namibia", "536": "Nauru", "429": "Nepal", "204": "Netherlands", "546": "New Caledonia", "530": "New Zealand", "710": "Nicaragua", "614": "Niger", "621": "Nigeria", "555": "Niue", "534": "Northern Mariana Islands", "242": "Norway", "422": "Oman", "410": "Pakistan", "552": "Palau", "425": "Palestine", "714": "Panama", "537": "Papua New Guinea", "744": "Paraguay", "716": "Peru", "515": "Philippines", "260": "Poland", "268": "Portugal", "330": "Puerto Rico", "427": "Qatar", "647": "Réunion", "226": "Romania", "250": "Russia", "635": "Rwanda", "356": "Saint Kitts and Nevis", "358": "Saint Lucia", "360": "Saint Martin (French part)", "358": "Saint Pierre and Miquelon", "360": "Saint Vincent and the Grenadines", "549": "Samoa", "292": "San Marino", "626": "Sao Tome and Principe", "420": "Saudi Arabia", "608": "Senegal", "220": "Serbia", "633": "Seychelles", "619": "Sierra Leone", "525": "Singapore", "231": "Slovakia", "293": "Slovenia", "540": "Solomon Islands", "637": "Somalia", "655": "South Africa", "450": "South Korea", "214": "Spain", "413": "Sri Lanka", "634": "Sudan", "746": "Suriname", "653": "Swaziland", "240": "Sweden", "228": "Switzerland", "417": "Syria", "466": "Taiwan", "436": "Tajikistan", "640": "Tanzania", "520": "Thailand", "615": "Togo", "539": "Tonga", "374": "Trinidad and Tobago", "605": "Tunisia", "286": "Turkey", "438": "Turkmenistan", "376": "Turks and Caicos Islands", "641": "Uganda", "255": "Ukraine", "424": "United Arab Emirates", "235": "United Kingdom", "310": "United States", "748": "Uruguay", "434": "Uzbekistan", "541": "Vanuatu", "225": "Vatican City", "734": "Venezuela", "452": "Vietnam", "543": "Wallis and Futuna", "421": "Yemen", "645": "Zambia", "648": "Zimbabwe" }; db.mower.aggregate([ { $project: { "_id": 0, "SerialNumber": {$ifNull: ["$_id", null]}, "BareToolNumber": {$ifNull: ["$info.bareToolnumber", null]}, "GardenDataSize": { $ifNull: ["$status.mowerStatus.operatingData.gardenData.size", null] }, "MapSize": {$ifNull: ["$status.mowerStatus.map.size", null]}, "FirmwareVersion": { $ifNull: ["$status.firmwareStatus.currentVersion", null] }, "MobileCountryCode": { $ifNull: ["$status.mowerStatus.networkStatus.mobileCountryCode", null] } } }, { $addFields: { "CountryName": { $cond: { if: { $in: ["$MobileCountryCode", Object.keys(countryCodeLookup).map(Number)] }, then: { $arrayElemAt: [Object.values(countryCodeLookup), { $indexOfArray: [Object.keys(countryCodeLookup).map(Number), "$MobileCountryCode"] }] }, else: "Unknown" } } } }, { $project: { "SerialNumber": 1, "BareToolNumber": 1, "GardenDataSize": 1, "MapSize": 1, "FirmwareVersion": 1, "MobileCountryCode": 1, // Include MobileCountryCode in the final output if needed "CountryName": 1 } } ])
Editor is loading...
Leave a Comment