So here is the question. I want to create a data structure given a set of input values.
Since this is a representation of several languages, we consider the list of input data as an array of key / value pairs. And so an array of Hash, Map, Dictionary or any other term that floats on your boat. I will keep all the notation here as JSON, hoping that it is versatile enough for translation / decoding.
So, for input, let's say we have the following:
[ { "4": 10 }, { "7": 9 }, { "90": 7 }, { "1": 8 } ]
Perhaps a little redundant, but let's stick with that.
So, from this input I want to get into this structure. I give the whole structure, but the important part is what is returned for the value under "weight" :
[
{ "$project": {
"user_id": 1,
"content": 1,
"date": 1,
"weight": { "$cond": [
{ "$eq": ["$user_id": 4] },
10,
{ "$cond": [
{ "$eq": ["$user_id": 7] },
9,
{ "$cond": [
{ "$eq": ["$user_id": 90] },
7,
{ "$cond": [
{ "$eq": ["$user_id": 1] },
8,
0
]}
]}
]}
]}
}}
]
, , , "", , , .
, , , , , , JSON .
, , user_id.
?
, , , .
, .
.