Is it possible to use match_specs to directly delete records from an mnesia table?
So far, the best I have been able to do is to run :mnesia.select to get the primary keys, and then to delete each one e.g.:
{:atomic, primary_key_list} =
:mnesia.transaction(fn ->
:mnesia.select(
MyTable,
match_spec_to_retrieve_relevant_primary_keys
)
end)
for pk <- primary_key_list do
{:atomic, :ok} =
:mnesia.transaction(fn ->
:ok = :mnesia.delete(MyTable, pk, :write)
end)
end
But I’m wondering if there is a way to do something like:
# NOT REAL CODE
:mnesia.transaction(fn ->
:mnesia.delete(
MyTable,
match_spec_to_retrieve_relevant_primary_keys
)
end)
Or else what is the best way to delete many records based on a match_spec?