3

This query works:

FOR person IN 1..1 INBOUND @companyID employed_by
    LET age = DATE_DIFF(person.age * 1000, @currentTime * 1000, 'y')
    COLLECT label = age WITH COUNT INTO value
        RETURN {data: label, frequency: value}

And gives me this:

[
    {
        data: 18,
        frequency: 69
    },
    {
        data: 19,
        frequency: 73
    },
    {
        data: 20,
        frequency: 86
    }
]

But what i really want is something like this

{
    data: [18, 19, 20]
    frequency: [69, 73, 86]
}

I was expecting the following query to work - but the PUSH statements fail (syntax error), i tried a bunch of PUSH statements in FOR loops but can't get them to work as i expect, which would imply i am doing something absolutely mental

LET data = []
LET frequency = []
LET temp = 
        (
            FOR person IN 1..1 INBOUND @companyID employed_by
                LET age = DATE_DIFF(person.age * 1000, @currentTime * 1000, 'y')
                COLLECT label = age WITH COUNT INTO value
                    data = PUSH(data, label)
                    frequency = PUSH(frequency, value)
                    RETURN true
        )
RETURN {data: data, frequency: frequency}

Any advice would be great!

4

1 回答 1

3

而且,经过更多的摆弄 - 这似乎正是我所需要的:

LET temp = 
    (
        FOR person IN 1..1 INBOUND @companyID employed_by
            LET age = DATE_DIFF(person.age * 1000, @currentTime * 1000, 'y')
            COLLECT label = age WITH COUNT INTO value
                RETURN {data: label, frequency: value}
    )
RETURN {data: temp[*].data, frequency: temp[*].frequency}
于 2016-05-13T18:31:55.440 回答