Getting the key of the document when querying via N1QL

Is it possible?

Something like

bucket.query(N1qlQuery.simple(“query here”)).allRows().get(0).value();

would give me the value, but can I obtain the key of the document when querying as such?

One option is project the docid as part of the select query

SELECT META(d).id AS docid, d.* FROM default AS d WHERE …

Thanks @vsr1, but is not needed select all the fields of the bucket, you can select only the ID of the documents.

Here you have the official documentation about that https://developer.couchbase.com/documentation/server/4.6/n1ql/n1ql-language-reference/metafun.html.