Selecting explicit fields, while keeping nested path

Hey there,
We have a scenario that we join 2 document using N1QL query, Let Say:
user:1 doc:
{ userId: 1, _order: "order:1" }

order:1 doc:

{
    status: 1
    _supplier: "supplier:1"
}

so, we join the user with her order document and get:

{
userId: 1,
order: {
    status: 1
    _supplier: "supplier:1"
   }
}

but we don’t need the _supplier: "supplier:1" field in our response, so we explicit choose the field we want order.status.
The problem is that the order.status field is no longer nested under order but show in the main namespace of the json structure.

so, to our question :slight_smile: -
Is there a way of explicitly selecting fields from joined document while keeping the fields nested under some namespace ?

Thanks,
Idan.

Hi,

You can construct any response you want in your SELECT list. For example:

SELECT userDoc.userId, { "status": orderDoc.status } AS `order`
FROM userDoc JOIN orderDoc ... ;
1 Like