Search code examples
javacouchbasedslsql++

Couchbase java N1QL DSL query statement with IN expression


Trying to write a N1QL query like

SELECT * from bucket
WHERE s IN ["s1", "s2", ..., "sn"]
END;

in DSL. Assuming I have a list of Strings called s_array, I need to write something like this:

select("*").from("bucket")
.where(x("s").in(s_array);

Whats the best way to write the IN expression in DSL without concatenating all list elements in a String or something?


Solution

  • You can do this with the JsonArray overload, as so:

    select("*").from("bucket")
                .where(x("s").in(JsonArray.from("s1", "s2", "s3"));