Retrieve referenced content from a list of references

Hello,
Can you help me retrieving the referenced content from a list of references ?
The scope of this data structure is to create a dictionary of json forms with exchangeable fields and values.
I have 3 types of docs : form (which may contain an array of references to subForms and an array of references of fields), field (which which may an array of references to values) and value (which may contain an array of references to other subValues ).

A form looks like :
{
“content”: {
“fields”: [
{“ref”: “field_0”},
{ “ref”: “field_1”},
{ “ref”: “field_2”}
],
“subForms”:[
{“ref”: “form_1”}
]
“label”: “exemple form”,
“name”: “form_0”,
“ref”: “form_0”
},
“dbId”: “FORM::form_0”,
“type”: “FORM”
}

A field looks like : 
{
  "content": {
    "values": [
      { "ref": "value_0" },
      { "ref": "value_1" }
    ],
    "label": "field test ",
    "name": "field_0",
    "ref": "field_0"
  },
  "dbId": "FIELD::field_0",
  "type": "FIELD"
}

Then a value looks like :
{
“content”: {
“subValues”: [
{ “ref”: “value_2” }
],
“label”: “value test”,
“name”: “value_0”,
“ref”: “value_0”
},
“dbId”: “VALUE::value_0”,
“type”: “VALUE”
}

I’m trying to find out a query to get as result a form completely fulfilled, in practice each “ref” should be replaced by the corresponding “content”. I’m new to N1QL, I tried different queries with NEST and JOIN clause but I’m unable to obtain the following result :

{
	"content": {
		"ref": "form_0",
		"label": "exemple form",
		"name": "form_0",
		"fields": [
			{	"ref": "field_0",
				"label": "field test ",
				"name": "field_0",
				"values": [
					{	"ref": "value_0",
						"label": "value test",
						"name": "value_0",
						"subValues": [
							{	"ref": "value_1",
								"label": "value1 test",
								"name": "value_1",}
						],
					},
				       { other values ...}
				],
			},
			{other fields...}
		],
		"subForms":[
		  {other forms...}
		]
	}
}

Any help would be appreciated, thanks.

SELECT f.conent.*,
       (SELECT f1.content.*,
               (SELECT v.conent.*
                FROM mybucket AS v USE KEYS f1.content.`values`[*].ref) AS values
        FROM mybucket AS f1 USE KEYS f.fields[*].ref) AS fields
FROM mybucket AS f
WHERE f.type = "FORM"

Thank you for your support, the query produces a result but I still have an error , in the result the fields arrays are empty. I don’t know whether it is linked or not but a warning indicates :
[
{
“code”: 0,
“msg”: "Document key must be string: "
}
]

I didn’t find anything about this error code.
I tried to reduce de degree of intricacy retrieving only forms and fields content (without values) and the fields arrays are still empty. I’m sure that the references are correct because I tried retrieving the entire form whit a “for” loop on my backend and it works correctly, the issue is that it’s really slow making one query per document. It would be great if I could retrieve the whole form at once

INSERT INTO default VALUES ("form_0", { "content": { "fields": [ {"ref": "field_0"}, { "ref": "field_1"}, { "ref": "field_2"} ], "subForms":[ {"ref": "form_1"} ], "label": "exemple form", "name": "form_0", "ref": "form_0" }, "dbId": "FORM::form_0", "type": "FORM" } );

INSERT INTO default VALUES ( "field_0", { "content": { "values": [ { "ref": "value_0" }, { "ref": "value_1" } ], "label": "field test ", "name": "field_0", "ref": "field_0" }, "dbId": "FIELD::field_0", "type": "FIELD" }),
                    VALUES ( "field_1", { "content": { "values": [ { "ref": "value_0" }, { "ref": "value_1" } ], "label": "field test ", "name": "field_1", "ref": "field_1" }, "dbId": "FIELD::field_1", "type": "FIELD" }),
                    VALUES ( "field_2", { "content": { "values": [ { "ref": "value_0" }, { "ref": "value_1" } ], "label": "field test ", "name": "field_2", "ref": "field_2" }, "dbId": "FIELD::field_2", "type": "FIELD" });

INSERT INTO default VALUES ( "value_0", { "content": { "subValues": [ { "ref": "value_2" } ], "label": "value test", "name": "value_0", "ref": "value_0" }, "dbId": "VALUE::value_0", "type": "VALUE" }),
                    VALUES ( "value_1", { "content": { "subValues": [ { "ref": "value_2" } ], "label": "value test", "name": "value_1", "ref": "value_1" }, "dbId": "VALUE::value_1", "type": "VALUE" });

SELECT f.content.*,
       (SELECT f1.content.*,
               (SELECT v.content.*
                FROM default AS v USE KEYS f1.content.`values`[*].ref) AS `values`
        FROM default AS f1 USE KEYS f.content.fields[*].ref) AS fields
FROM default AS f
WHERE f.type = "FORM";