Search code examples
phparangodbaql

AQL query to filter for 2 nested values


I have a document with some translations. I want to fetch two languages, from one query, instead of having to run it twice. The reason for two is that English is the default, and will be used if the other selected language does not have a translation.

So I have structured as below, and I'm not wondering, how can I filter out so I only get the selected languages, for example "en" and "es". Excluding all the "de" values from the arrays.

texts:{
  id1:{
    "en":"welcome",
    "es":"bienvenido",
    "de":"Willkommen "
  },
  id2{
    "en":"good bye",
    "es":"adios",
    "de":"tschüss"
  }
}

So for example, what would the query look like if I wanted the "welcome" text, in english and spanish. I would pass in "id1" for the word, and "en" and "es" for the keys. This is where I am stuck, I just dont know how to do the filtering.

FOR doc IN translations
FILTER doc.texts.id1.... == "en" AND "es" .....

RETURN doc

I'm running the AQL queries from PHP if that is of any importance.

grateful for any help, thank you!


Solution

  • Let try:

    FOR doc IN translations
    FILTER (doc.texts.id1.en != NULL) AND (doc.texts.id1.es != NULL)
    
    RETURN doc