Like Query on Concatenation of two fields in Couchbase Lite


We have to create a like query on the concatenation of two fields, say First Name and Last Name on Couchbase Lite 2.1.

We are using the below query and not getting any results.
Can anyone please help.

We are using the query given below :-

String searchTerm = “%Harsh Mehlawat%”;
Query query =“ID”))
.add(Expression.string(" ")

add is for numeric operations. There is no string concatenation operator in the query builder yet. I’d suggest doing the reverse and parsing the first and last name out of the search term and then using an and operation.

we may also want to add middle name in between which will make complexity higher and produce unwanted result. Secondly search term will not be having complete data.

Better we can have a field in the document as fullName which can be concatenated while saving the data. Which makes everything easy.


Should become a priority feature. Along with unnest functionality.

@househippo, @priya.rajagopal, @jens should I create a ticket for this. Or it is already in backlog.

Pankaj Sharma

The concatenation operator already exists in couchbase-lite-core; we’d just need to add it to the public query-builder API.

Our API issue tracker isn’t public, but I’ve just filed this as an issue.


Thank you @jens . Have you filed issue for both unnest and concatenation?

Unnest is already in development.

Please file both UNNEST and concatenation requests with specific use case description through the Accounts team. They are on our radar but your request will help with the prioritization.

Sorry to ping an old post, but just wondering if there is any news on concat ?

Hasn’t made it into our roadmap as yet. Can you provide a concrete example of the type of query that you are looking for in your use case.

Say I have .schema.namespace and .schema.class properties on some documents that represent the types they should parse to, and I want to select a particular sub-set of these based on the combination of both fields.

// Kotlin
// compatibleSchemas expressed as `"${namespace}.${class}"`.
val compatibleSchemas = listOf("MyNs.MyClass", "MyNs.MyClass.SubType", "OtherNs.MyClass")
    .map { Expression.string(it) }

val schemaExpr =".schema.namespace")

// in query builder:

This particular example could be done with and and or, but that will not work for large numbers of compatibleSchemas:

CouchbaseLiteException{domain='CouchbaseLite', code=23, msg=JSON parse error: JSON error: LEVELS_EXCEEDED}

Hi, any news about string concatenation?

Hasn’t made the roadmap yet. You can track it here. Can you provide an example of your use case.
Until then, you will have to use the AND operator to filter the results …