Question:
What I want is to loop over on the values of a field during the Mongo project,
For Example: Here is a small sample of my data
{
"_id": ObjectId(1),
"field1": {
"key1":"value1",
"key2":"value2"
}
},
{
"_id": ObjectId(1),
"field1": {
"key1":"value1",
"key2":"value2",
"key3":"value3"
}
}
}
And my query is something like this:
MyDocument._get_collection().aggregate([
# some match statement
"$project": {
'customized_data': {
'$ifNull': ['$field1.key1', "default_value"]
}
}
])
So my query is suitable just for one key. (key1 from field1).
So how can I loop over "field1"
values ("key1":"value1", "key2":"value2", "key3": "value3")
and in order to a specific condition change output?
NOTE:
I'm using the latest version of MongoDB4.2
so far