How to show the query result ans total count together?

Hi,

Suppose I have a select query that returns result like this:

{
"results: [
// some results
]
}

Now I want to add a total field at the top like this:

{
“body”: {
"total: 5
},
"results: [
// some results
]
}

How can I do this?

metrics.resultCount has total, You can build which ever object you want in application or SDKs , it is not possible in the N1QL.

{
    "requestID": "7f9ee55f-44c7-4a1d-ad6e-1fd00f0fe41d",
    "signature": {
        "$1": "number"
    },
    "results": [
    {
        "$1": 0
    },
    {
        "$1": 1
    },
    {
        "$1": 2
    }
    ],
    "status": "success",
    "metrics": {
        "elapsedTime": "1.36467ms",
        "executionTime": "1.290719ms",
        "resultCount": 3,
        "resultSize": 69
    }

No, no, not this way. Suppose the query is paginated with LIMIT 10 and OFFSET 0, then how will you show the total amount?

If you are paginating you need to issue two separate queries and merge results in application.
You can’t combine aggregate query and non aggregate query (i.e. results + count)