I just started using Fauna and looks awesome!
I’m struggling to understand when to use indexes and when not to use them for filtering.
For example, let’s assume we have a collection with hundreds of thousands of documents of clients with 3 fields, name, monthly_salary, and age.
How can I search for documents that monthly_salary is higher than 2000 and age higher than 30?
In SQL this would be straightforward but with Fauna, I´m struggling to understand the best approach because terms of Index only work with an exact match. I see in docs that I can use the Filter function but I would need to get all documents in advance so it looks a bit counterintuitive and not performant.
Below is an example of how I can achieve it, but not sure if it’s the best approach, especially if it contains a lot of records.
Map( Filter( Paginate(Documents(Collection('clients'))), Lambda( 'client', And( GT(Select(['data', 'monthly_salary'], Get(Var('client'))), 2000), GT(Select(['data', 'age'], Get(Var('client'))), 30), ) ) ), Lambda( 'filteredClients', Get(Var('filteredClients')) ) )
Is this correct or I´m missing some fundamental concepts? can anyone help?
Thanks in advance,