Search code examples
javaorientdb

Querying an embedded list in OrientDB


I have a document in my OrientDB database (version 1.0.1), with a structure largely like this:

{
    "timestamp": "...",
    "duration": 665,
    "testcases": [
        {
            "testName": "test01",
            "type": "ignore",
            "filename": "tests/test1.js"
        },
        {
            "iterations": 1,
            "runningTime": 45,
            "testName": "test02",
            "type": "pass",
            "filename": "tests/test1.js"
        },
        ...
        {
            "testName": "test05",
            "type": "ignore",
            "filename": "tests/test1.js"
        }
    ]
}

How can I query across the entire list, eg. if I want to find all documents that contain a testcase with the type "ignore"?

I've attempted the following query

select from testresult where testcases['type'] = 'ignore'

but this results in a NumberFormatException.

select from testresult where testcases[0]['type'] = 'ignore'

works, but obviously only looks at the first list element of each document.

select from testresult where testcases contains(type = 'ignore')

Doesn't provide any results, but the query is accepted as valid.

Update: The following query works as intended, if the testcases are stored as separate documents instead of as an embedded list.

select from testresult where testcases contains (type = 'ignore')

Solution

  • I know it's an old question but I had the same problem and just stubled upon an answer here: https://www.mail-archive.com/[email protected]/msg00662.html

    The following should work. It does in my very similiar use case.

    select from testresult where 'ignore' in testcases.type