In our system we need to know if a reference to a specific document ID exists anywhere in the database. (for example to allow/deny deletion)
This previously worked fine with a view we created but now we have been asked to do the same thing using Cloudant query selectors.
We came up with the solution below where we include all possible paths where a document reference would be found. The query is generated dynamically to include all possible paths for a "foreign key" reference, however this mean it would need to scale to potentially +100 unique paths (ie, the $or operator array might end up with +100 items)
I wonder if such a large query would even work and also the potential performance implications. Also if there's an alternative way we would like to know.
{
"selector": {
"$or": [
{
"content": {
"$elemMatch": {
"accounts": {
"$elemMatch": {
"bank": "bank12345"
}
}
}
}
},
{
"content": {
"$elemMatch": {
"partners": {
"$elemMatch": {
"someEntity": "someReference12345"
}
}
}
}
}
]
},
"fields": [
"_id",
"_rev"
]
}