1

I have a couchbase bucket, in it I have an Integer data with a key.

I am incrementing it, using the API "increment" so I cannot put a JSON there with the date of the last updated.

The question is, how can I select ALL element that where changed today/yesterday?

1

1 Answer 1

1

You have a few options depending on what services you use in Couchbase.

The easiest way that I have used (since v4.6) is query via Couchbase's SQL-like N1QL language and the meta().cas value.

For example, CAS value converted to a timestamp and truncated down to seconds works well, though it's largely undocumented and historically not recommended for this use. Now it represents revision time (more or less, beyond scope here).

A query for documents before today would look something like this (sorry it's not elegant, probably a better way):

SELECT meta().id, 
((NOW_MILLIS())/1000 - meta().cas/1000000000 )/86400 as days_before_today 
FROM bucket1 
WHERE meta().cas/1000000000  <= (NOW_MILLIS())/1000-86400

Note: 86400 seconds in a day, sub in your own timestamp for WHERE clause or change to reflect the range you are interested in.

Obviously if you were able to add a revision timestamp value to the document you'd have more full control over the value.

You could probably also use TTL value settings on the doc though sounds like you do not specifically want to expire documents.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.