How to use array of objects in Couchbase Expression

Hi,

I have problems in building an expression based on array of objects. Didn’t found a way to access
A filter(Couchbase expression) is set to query for documents:
Query.Select(…).Where(expression)

and the structure of a document looks like this:
company{
id
_typename
name
companytype
owner
detail{
mobile
fax
}
subsidiary{
[ {
city
streetname
} ]
}
}

If I want to have all the companies with the companytype = 2, the expression will be Expression.Property(“companytype”).EqualTo(2).

But how can I take all the companies for which subsidiary.city = Berlin (= at least one object from the array has the city = Berlin).

What I found on the documentation is how to set an expression on a simple array, for example array of strings:
Expression.Any(“x”).In(Expression.Property(“phones”)).Satisfies(Expression.Variable(“x”).EqualTo(3));

But how can I do it for an array of objects, by accesing one or more properties of each object of the array (city, streetname)?

Thanks
Ramona

Hi Ramona,

eg An object with a list of representatives that have a name property valued “Bart”.

Query.Select(SelectResult.Expression(Expression.Meta().ID).As("id"))
            .From(DataSource.Database(db))
            .Where(Expression.Any("representative").In(Expression.Property("representatives"))
            .Satisfies(Expression.Variable("representative.name").EqualTo("bart")))

eg a company document with subsidiary “Berlin”. I would guess on the top of my head

Query.Select(SelectResult.Expression(Expression.Meta().ID)
                      .From(DataSource.Database(db))
                      .Where.Expression.Property("subsidiary.city").Is("Berlin")

The example that I provided in this post should help you. You use Array Expression for this similar to @thomas1983 suggestion …