Accessing query metadata without iterating through the results

Hi,

I am running into an issue and after much research can’t seem to find the answer to it. Here is the situation: using the gocb v2 Go SDK, after running a query, I can’t access the metadata unless I iterate through the results.
Based on the documentation, it seems that I should be able to access the metadata right after running the query, without having to iterate through the results. Here is the sentence that leads me to believe that:

Once a result returns you can iterate the returned rows and/or access the QueryMetaData associated with the query.

Here is my code: queryStr := "UPSERT INTO test (KEY, VALUE) VALUES("key::1", "{"id": "1", "name":"foobar") RETURNING *"
results, err := globalCluster.Query(queryStr, &gocb.QueryOptions{ Metrics: true })

According to the documentation, once I have called the Query function, if I don’t have any error, I should be able to access the metadata, but if I run this code: metadata, _ = results.MetaData(), and then check the value of metadata, I get <nil>, whereas, if before calling metadata, _ = results.MetaData(), I call results.One or results.Rows then I get a proper value for metadata.

My question is: should I be able to access query metadata without having to iterate through the results? If yes, I will open an issue on github for it, but I wanted to double-check before doing that.

Cheers,
Bertrand.

Hi @Bertrand_Sirodot it seems that we have a documentation issue there, you cannot access metadata until the rows have been iterated. In the case where you queried for a large number of rows then we would stream the data and the metadata comes later than the rows in the stream so we cannot expose metadata until all rows have been read to cover that case. results.One will actually take the first row and iterate any remaining rows “under the hood”.

I’ll make sure that we get the documentation updated to be more clear on this.