Use of Array For IN statement in N1QL - SDK Couchbase

Hi All,

I am trying to run a select query with an IN statement using N1QL ,

JsonObject Val = JsonObject.create().put(“Data1”, Arrays.asList(1,2)).put(“CurrDt”, CurrentDate);
String query="select * from TABLE where field IN $Data1 and Date = CurrentDate;
N1qlQueryResult result1 = bucket.query(N1qlQuery.parameterized(query,Val));

The above code is running into errors,

“Error-java.lang.ClassCastException: com.couchbase.client.java.document.json.JsonArray cannot be cast to java.lang.String”.

Is there something wrong with the above approach or can you suggest other ways to pass a dynamic array of string into “IN” statement?

Any help would be much appreciated.
Thanks in advance!

Thanks
Alponnu

@alponnu can you print out your exact query string and go to Query web ui and execute that?

When the values are hardcoded, able to execute from the java code as well.
But when the array is passed thru’ JSONArray, unable to execute.

Thanks
Alponnu

Hi @alponnu,

Which version of the java-client are you using? I tried to reproduce this using 2.7.2 client and couldn’t.

Thanks.