Help required regarding conditional query in Couchbase through JAVA SDK

#1

We are migrating from Oracle to couchbase.

Below is the scenario where i need to fetch the records based on some condition’s.
I don’t want to load all the documents on Java side and then apply the logic as there might be millions of documents in production.

Below is my scenario :

There are Session documents that contain fields like Status,Type and CreatedDate.
I want all the Session documents where status is “Active” , Type is {:someType} and CreatedDate >= {:someDate}

Could you please provide your inputs on this , how can implement it in couchbase.

#2

There are three ways to model this:

  • You can use a view which indexes your document in a way such as (they key): [status, type, createdDate] … now on query time you query for a range where the end range is [“active”, “type”, “yourdateformat”], for example a unix timestamp or some other format…
  • If you are developing right now you can start using N1QL, which might make it more easy since your oracle queries can be very easily transferred over to N1QL
  • Use key/value only and maintain a separate document which contains primary keys of all documents that satisfy your criteria.

Each of those approaches has its own pros and cons, but the view approach will be pretty solid I think. If you are starting on development and you plan a larger oracle migration, going with N1QL might pay off as well.