0

I have the following data model declared:

toto = { name : "toto1" tata_list : ["id1", "id2", "id3", ...] }

With the OPA database query syntax, can I retrieve the "toto" model that contains a specific "id" in his "tata_list" attribute ?

Something like:

myToto = /toto/toto[tata_list contains "id1"]

Or do I have to browse all the "toto" and search for each of them if the tata_list attribute contains my ID ?

Thanks!

gogson
  • 930
  • 2
  • 8
  • 11

1 Answers1

1

This is so called "hole expression" in Opa: [_]. For the database value of list type:

list(anything) /my_db/my_list_val

the path my_list_val[_] in the query refers to any element of the list.

In chapter Querying / Sub-queries of the manual (in the WIKI) the example:

dbset(_, _) x = /dbname/complex[smap["key"].lst[_] == "value"]

finds the documents based on the list(string) value named lst. If list (actually, record with string map where key is "key" and value is nested record with field lst) contains string "value", then it satisfies the search condition.

In your case, the query could be:

myToto = /toto/toto[tata_list[_] == "id1"]
Marcin Skórzewski
  • 2,854
  • 1
  • 17
  • 27