Query parent/child relation

Hi,
I need support for building an expression based on an array of ids. I want to receive data from those ids in one query.
I use Couchbase Lite v.2.
My data looks like:

account:
{
name
refids
[
id
]
}

contact person
{
name,
address
{
street,
city
}
}

What I want is to query the account and receive all properties of the contact person in one query.

Thank

You can do a inner JOIN query on the two documents based on the id contained in the refIds array. I am assuming here that the “id” in the “refIds” array corresponds to a contact.

There is an example that does almost what you want in this blog post …look at section on “JOIN Expressions with Functions”

That said, there seem to be couple of issues in your data model

  • Your contact person document would need an “Id” property that would be referenced in the “refIds” property in the “account”. Otherwise you cannot correlate or join the documents.
  • I would also advise you to model your data to include a “type” field that can filter the subset of documents that you are operating on and make the query efficient.
    Here is a primer on that.