Chaining of queries

Hi,
We are using couchbase in our project.
I need to write a query for a use case where:

  1. I get the earliest expiring “case” (Field name: expiryTimestamp)
  2. If multiple docs are there for same earliest expiryTimestamp then I have to check for field “caseType”.

What would be the best way to achieve this?
Please suggest.

Thanks

CREATE INDEX ix1 ON mybucket(expiryTimestamp, caseType);
SELECT *
FROM mybucket 
WHERE  expiryTimestamp IS NOT MISSING
ORDER BY expiryTimestamp, caseType
LIMIT 1;

You can Also use MIN() on Array of fields

SELECT MIN([expiryTimestamp, caseType])
FROM mybucket
WHERE  expiryTimestamp IS NOT MISSING
1 Like