Let's suppose I have a collection named "repos" containing objects like this one:
{
name: 'myrepo',
actions: [
{ timestamp: '2016-04-12T14:43:20Z', change: 'add' },
{ timestamp: '2016-04-12T14:45:10Z', change: 'remove' },
{ timestamp: '2016-04-12T15:03:03Z', change: 'add' },
... and so on ....
]
}
Now I want a query to convert each of these objects into something like this:
{
name: 'myrepo',
timestamps: ['2016-04-12T14:43:20Z', '2016-04-12T14:45:10Z', '2016-04-12T15:03:03Z'],
changes: ['add', 'remove', 'add']
}
I have thought of something like the following:
FOR r in repos
LET changes= (FOR a IN r.actions RETURN a.change )
LET timestamps = (FOR a IN r.actions RETURN a.timestamp)
RETURN {
name: r.name,
changes: changes,
timestamps: timestamps
}
but I am afraid that the double FOR may be not very efficient.
Any suggestion?