1

I have collection of documents. Document have a field which value is an array of maps (for example: map with one field name). Structure is like that:

{
  arrayfield: [
    {
       name: "value1",
    },
    {
       name: "value2",
    }
  ]
}

I want to fetch documents whose arrayfieds all maps contain values from specified array. Documentation says that I can use containsall operator. I use it in this way:

select from SomeCollection where arrayfiled containsall (name in ['value1','value2'])

But this construction always returns empty result. Where I do mistake? Thanks.

PS: If my question not understandable, I can post more detailed example of the collection and and a result which I want to receive.

bartl
  • 392
  • 2
  • 11
  • What type is the property arrayfiled ? – Alessandro Rota Nov 09 '15 at 09:21
  • Can you post the result of the following query "select from SomeCollection" ? I would understand if arrayfiled is of type embedded, embeddedList, embeddedSet, emnbeddedMap, link, linkList, linkMap, linkSet – Alessandro Rota Nov 09 '15 at 13:44
  • I can do it later. May be if it will help: I work with `baasbox` which uses OrientDB – bartl Nov 09 '15 at 13:57
  • @AlessandroRota here is the respond with I can get from baasbox: `[ {"@rid":"#26:3", "@version":17, "@class":"SomeClass", "title":"some title", "arrayfield":[ {"name":"value1"}, {"name":"value2"} ], "projectid":"e251799e-8706-4eb8-a414-ad8524b00edb", "id":"7ebe866e-53a0-472d-96a1-98982e9ab274", "_allowRead":[{"@rid":"#4:4","@version":4,"@class":"ORole","name":"anonymous","isrole":true}], "_allowUpdate":[{"@rid":"#5:5","@version":1,"@class":"OUser","name":"bartl"}], "_allowDelete":["#5:5"], "_author":"bartl"} ]` – bartl Nov 09 '15 at 16:22
  • @AlessandroRota I used this request to determine the type of field: `select arrayfield.type() as type from SomeClass` and it returned `EMBEDDEDLIST` – bartl Nov 09 '15 at 19:40

2 Answers2

2

Found a solution to solve my issue without containsAll:

select from SomeCollection where not (arrayfield contains (fname not in ["value1", "value2"]))

bartl
  • 392
  • 2
  • 11
0

Try the following query

select from SomeCollection where arrayfiled.name contains "value1" and arrayfiled.name contains "value2"

enter image description here

Alessandro Rota
  • 3,560
  • 1
  • 8
  • 10
  • Thanks for the answer. But it's not exactly what I need. Let me describe the situation. I have the array of strings: [value1, value2, value3, ...] (from network request). And I need to query documents that satisfy next condition: **all** its elements in the `arrayfield` must have name from the passed array of strings. And length of the string array may be greater than the number of elements in the `arrayfield` – bartl Nov 10 '15 at 13:48
  • Query have to return rows 10:1, 10:2, 10:3 and 10:7 from your test example for input string array `["value1", "value2"]`. – bartl Nov 10 '15 at 14:06
  • Also I can modify `where` clause of the query in runtime, if it helps t solve this – bartl Nov 10 '15 at 14:15
  • To see if I have understood. For the case with only two parameters, the following query would work well? select @rid,arrayfiled.name from (select expand($d) let $a= ( select from SomeCollection where arrayfiled.name contains "value1" and arrayfiled.name contains "value2"), $b= (select from SomeCollection where arrayfiled.name contains "value1" and arrayfiled.size()=1), $c= (select from SomeCollection where arrayfiled.name contains "value2" and arrayfiled.size()=1), $d= unionAll($a,$b,$c)) – Alessandro Rota Nov 10 '15 at 15:01
  • Because it has the element with name=value3, which is not in the string array [value1, value2]. And I'm sorry, there is a mistake in the my second comment, querry should return 10:1 10:2 10.3, and should not 10:6 and 10:7. Replacng AND to OR will not help here. – bartl Nov 10 '15 at 15:02
  • try this query select @rid ,arrayfiled.name from someCollection where arrayfiled containsAll ( name = "value 1" or name="value 2" ) – Alessandro Rota Nov 10 '15 at 15:09
  • Wow, Why I didn't think about this variant ... It should work, I'll check it later. I let you know about the result. Thanks for your help! – bartl Nov 10 '15 at 15:13
  • Unfortunately, It does't work :(. Seems that containsAll isn't implemented at all, or I use this in wrong way :( – bartl Nov 10 '15 at 17:37