Couchbase Lite 2 - query to get documents filtered by input array of strings

I want to write a query for documents with certain “identifiers”.
The document has a property called “identifier”.
The query should take an array of identifiers and return documents that are matching them.
The Input array is not a property of the document. It is simply an array to create the query.

Input Array [“identifierA”, “identifierB”, “identifierC”]
Document property [“identifier” : String]

I managed it to query all documents without a filter:

What I need is probably something like this:
.and(ArrayFunction.contains(ArrayExpression.any(Expression.string(“identifier”)), value: identifiers)
–> “identifiers” is an array of Strings

I’ve spent a whole day reading the documentation, your blogs and sample code but could not find what I need.

Kind regards,

The query should be of the form “WHERE identifier IN (…list of identifiers…)”. I don’t recall the exact syntax in the public API for an “IN” expression, sorry. (I work on the query engine but not on the API layer.)

i am having the same issue, but i don’t think its possible, you can test if a value exists in a document array but not if a property value is contained by a given array.
however since the api is flexible the in expression can be converted in a series of or clauses:

 val dbchanged= DatabaseChangeListener()

        var whereExpr:Expression?=null;
         for(docid in it.documentIDs)

This should work just as an in , but could someone kind at couchbase tell us if there is a limit on how may or conditions can be put in an expression ?

I don’t believe there is any limit imposed. But there may be other implications. How many conditions are you planning on chaining?

about 40 expressions

Your In list needs to be an array of Expression.String

This worked for me…

       //String array
        string[] identifiers = new string[] {"identifierA", "identifierB", "identifierC"};

        //Initialise your Expression array 
        IExpression[] expIdentifiers = new IExpression[identifiers.Count()];

        //Convert the string array into an Expression array
        for (int i = 0; i < identifiers.Count(); i++)
            expIdentifiers[i] = Expression.String(identifiers[i]);

        //Build the query 
        var query = QueryBuilder.Select(SelectResult.All())

Hope it helps!