I have for example this type of documents.
{
"name": "sylvie dupont",
"age": 25,
"accounts": [
{
"name": "BankOfAmerica",
"amount": 33
},
{
"name": "GoldBank",
"amount": 578
}
]
},
{
"name": "marie friconnet",
"age": 40,
"accounts": [
{
"name": "SaxonBank",
"amount": 896
},
{
"name": "BankOfAmerica",
"amount": 89
},
{
"name": "GoldBank",
"amount": 64
}
]
},
{
"name": "sylvie houmeau",
"age": 23,
"accounts": [
{
"name": "BankOfJapan",
"amount": 677
},
{
"name": "BankOfAmerica",
"amount": 556
},
{
"name": "BankOfEurope",
"amount": 653
},
{
"name": "GoldBank",
"amount": 267
}
]
}
I have to filter and order them dynamically according to whether the field exists or not (inside accounts field).
For example if there is SaxonBank I have to filter on SaxonBank but if there is BankOfAmerica then I forget SaxonBank for use BankOfAmerica, if BankOfEurope exists then I filter on BankOfEurope etc, and not on the others.
If none of these three banks exist then I order my documents using the GoldBank field which always exists.
I don't have to deal with the other bank fields at all if when the "priority bank" is present.
(here are example data to illustrate my need)
At this stage, I understood that I could use scripts to filter and order but it seems to me complex that's why I would like to take your opinion on the method to use before doing tedious research
thank you very much for your help