How to control field order in Couchbase N1QL response?

Viewed 356

How can I organize the json or table that the query show me? This in chouchbase with n1ql.

example:

select rol, count(*) as cantidad from PPS where type='Usuario'
group by rol

result
[
  {
    "cantidad": 2,
    "rol": "8847cda1-cf52-4af0-880c-5f7c5a281348"
  },
  {
    "cantidad": 2,
    "rol": "ef35059f-5953-4da7-b5d5-ee0f9a1c893f"
  }
]

I need rol first

2 Answers

I'm sorry, but what you're asking for isn't possible. Within each object the fields are returned in sorted order by name. You could rename the fields to something like "1_rol" and "2_cantidad", but that's the best that N1QL can do.

You might also alias the attributes in the select so that they auto order the way you want: “select rol as 1, candidad as 2...”

Or, order them into an array: “select [rol, candidad] as _res...”

Related