Selecting from subquery


I’ve got a document with structure like that:

    "elements": [
        {"foo": "bar", "value": 123},
        {"foo": "baz", "value": 456},

I’m trying to select values from that elements array. I’ve tried this:

SELECT a.* FROM (SELECT elements FROM default WHERE Meta().id = <my document's id>) WHERE = "bar"

but it doesn’t seems to work. Can I do this?

BTW I’m using couchbase server version 4.5 if that matters.

Each sub-object as separate object

FROM default AS d
UNNEST d.elements AS e
WHERE Meta(d).id =  "id" AND  = "bar";


Original format and filter array elements

SELECT d.*, ARRAY v FOR v IN d.elements WHEN = "bar" END AS elements
FROM default AS d
WHERE Meta(d).id =  "id" ;