Database / Mnesia intermediate to advanced Interview questions
What is the difference between mnesia:match_object/1 and mnesia:select/2?
Both let you query beyond a simple primary-key lookup, but match_object/1 uses a simpler,
pattern-only interface, while select/2 supports full match specifications with guard conditions.
| mnesia:match_object/1 | mnesia:select/2 |
| A single pattern with `'_'` wildcards; returns whole matching records. | Pattern + guard conditions (e.g. comparisons) + a custom result shape. |
| Simple to write for straightforward field-equality matches. | More expressive: supports `>`, `<`, `andalso`, and returning only specific fields. |
mnesia:match_object(#person{age = 30, _ = '_'}). %% vs. mnesia:select(person, [{#person{age = '$1', _ = '_'}, [{'>', '$1', 30}], ['$_']}]).
Use match_object/1 for a quick equality-style filter; reach for select/2 once you
need comparisons, combined conditions, or a projection that returns less than the full record.
More Related questions...