Couchbase Lite Join multiple records

Hi everyone! I I have the following documents:
Person

{
    "vehicle": {
        "couchId": "someid"
    }
}

OtherThing:

{
   "name": "thing one",
   "vehicle": {
     "couchId": "someid"
  }
}

{
  "name": "thing two",
  "vehicle": {
      "couchId": "someid"
  }
}

I need to get all person with other thing names. I used join for this purpose.

QueryBuilder
        .selectDistinct(
             SelectResult.expression(Expression.property("name").from("others"),
             ....
         )
         .from(datasource.as("persons"))
          .join(Join.leftJoin(datasource.as("others")).on(Expression.property("vehicle.couchId").from("persons").equalTo(Expression.property("vehicle.couchId").from("others"))

but when I am executing this query I’m receiving only one string, but I want to an get array like this ["thing one", "thing two"] for each matched person. How can I get this behaviour? How can I transform multiple matched items in my join to an array not to single item in the SelectResult?

I wanted to use group by and array_agg function for this, but couchbaselite for android doesn’t support array_agg((

Thanks in advance.

The query engine in Couchbase Lite Core supports array_agg, but for some reason Couchbase Lite’s public API doesn’t. @pasin, any idea why?

You can work around this by doing the aggregation yourself, scanning the rows returned by the query and combining multiple names.

Thanks! So, I did my task via my custom objects combination after executing query with the join. It really would be awesome if the public API also had this function to prevent boilerplate code like this

I filed an issue to add that function to the public API.

2 Likes

Was just searching for this, would be nice to have :slight_smile:

We haven’t scheduled to add the API to CBL.

CC: @priya.rajagopal