How can I leverage the CAS to get the upserted timestamp, using n1ql

Hello,
I am currently debugging some application flow issue, one of our apps emmits events to a topic and at some point in time those events are picked by a consumer and upserted to couchbase, our problem right now consists of a delay from when the events are emitted to when they are eventually upserted to CB.

There is a lot going on in between, so I am looking for a way to get the point in time when CB received the document, so that I can compare it with the timestamp (which is in the document we created), created right at emission time and calculate the travel time.

To that end, I have seen a few people suggesting to use CAS as a mean to get some sort of time stamp, this seems to be exactly what we need.
Some person running version 4.7 suggested using something like this in stack overflow:

 ...N1QL: SELECT meta().cas/1000000000 ...

we are currently using version 6.0.1, when I issue a query such as that I get a number that when converted to years gives that the document is around ~50 years old…
Maybe I am doing something wrong or, that doesn’t seem to work anymore. Is this something that is still available to us in our current version?

The concrete questions is, how can I leverage the CAS to get the upserted timestamp?

We are not modifying these events after the upserts, so the CAS never changes.

Hi @Carlos_Sanchez
CAS is intended to be an opaque long used solely for optimistic concurrency, so it’s not advisable to make any assumptions about how it’s generated.
It sounds like you’re mostly trying to debug where the delays are coming from at this point, e.g. whether it’s Couchbase or another component? Presumably you can timestamp when the consumer receives a given event, when it starts sending it to Couchbase, and when it receives the response?

This came up again recently.

You shouldn’t. The xattr last_modified is available for this.

@Test
void macros() {
String id = UUID.randomUUID().toString();
collection.upsert(id, JsonObject.create().put(“text”,“hello”));

LookupInResult result = collection.lookupIn(
  id,
  Arrays.asList(
    get(""), // omit this to avoid retrieving the document
    get(LookupInMacro.LAST_MODIFIED).xattr()
  )
);

System.err.println(result.contentAs(0, JsonObject.class));
System.err.println(result.contentAs(1,Integer.class));

}
{“text”:“hello”}
1706740531