Select multiple properties in an ARRAY clause in N1QL

n1ql

#1

Currently, I can do the following

ARRAY friend.name FOR friend IN friends END

which gives me an array of names for the array of friends. Suppose I want the array to contain objects like so

{
   name: "John Doe",
   status: "His status"
}

it is tempting to do something like

ARRAY friend.name, friend.status FOR friend IN friends END

However, this doesn’t work.
Any help would be greatly appreciated.


#2

Here is what you can do – wrap the properties in an object:


#3

Fantastic! Thank you.

I was looking for this wrapping json in queries functionality in the n1ql language reference but couldn’t find it anywhere. Is it written in there?

Thanks.


#4

Sent a note to our docs team. In general, you can construct objects anywhere within your query.