I am trying to figure the best approach to delete multiple items by ref, but only if 2 of the items’ fields equals some value.
In SQL I’d write it like this: DELETE from MyTable WHERE id IN (id1, id2, id3) AND formId='foo' AND accountId='Bar'
Here’s what I’ve got. It feels too complicated. Is there a better way?
If the submissionIds list is small, it seems to me that reading the docs and filtering on them is efficient (limits read ops).
If by chance the “submissions” are coming from a different index, then you could intersect that set with an indexes with terms data.formId and data.accountId. Something like this? But that does assume a lot.
Thanks @ptpaterson. I didn’t know about Intersection.
Your solution looks much more concise than mine.
You mentioned read-efficiency. Can you explain how your solution will be executed in terms of read/write operations?
I have 2 main use cases -
A user selects a list of submissions by checking checkboxes. In this case the list is likely to be short (what is “short” in your view btw?).
A user checks “select all” in the UI. In this case the list can be long, but instead of list of specific IDs, I will just have a filter. In this case I think I’ll just paginate on a relevant index and call Lambda(Delete) .
The Set operations, e.g. Intersection, will only work with two Sets or two Arrays but not on both at the same time. So in case #1 (user selects a list…) the intersection method is not going to work. I think there is a complicated way to make it work, but it’s at least as expensive as just reading the documents and filtering.
Each Get will cost a Read Op, of course. Paginate costs a Read Op for each Match(Index(...)) involved. For example, Paginiate(Match(Index(...))) costs 1 read op. If you Match on two Indexes and Intersection them, that’s 2 Read Ops.
EDIT: Different Set operations work differently, and I shouldn’t generalize the pricing. You should run queries and inspect them, either in the cloud shell or headers from the web requests. Cross referencing a discussion related to the cost of Set operations.
Mapping over a single index to Delete should cost 1 read op and N write ops, where N is the number of results.