Let's say I have this document:
{
"body": {
"items": [
{
"id": 1,
"person": {
"id": 100
}
},
{
"id": 2,
"person": {
"id": 101
}
}
]
}
}
I'm trying to create a query that will select documents based on an id of a person within my items array. So far I've come up with this:
SELECT * FROM c WHERE ARRAY_CONTAINS(c.body.items, { 'id': 1 }, true)
This works for selecting based off the item of the item object itself, but if I try to do this:
SELECT * FROM c WHERE ARRAY_CONTAINS(c.body.items, { 'person.id': 100 }, true)
It doesn't work.
I'm trying to build my query such that I could do a query where it should check for documents containing person.id = 100 and person.id = 101, but for now I just want to get the main part working.
How can I fix my query to allow me to search inner objects with the ARRAY_CONTAINS function, or is there a more intelligent way to do this?
Edit:
I also tried:
SELECT * FROM c JOIN i IN c.body.items WHERE i.person.id = 100
This works, but I need to be able to query on multiple people, so something like
SELECT * FROM c JOIN i IN c.body.items WHERE i.person.id = 100 AND i.person.id
Wouldn't work since it'd be expected an item to have a person.id equal to 100 and 101, which is impossible.