Reputation: 1057
So I am working on an idea for a "dating app" (I know who would have thought) and searching for what kind of Serverless Service I should use for the BE.
Until now I worked with GCP and Firebase, that's why I thought I could also use Firestore as my Database.
The problem is, that I would like to do complex filtering like the following:
.where(“date”, “>=”, today).where(“date”, “<=”, today + 3)
.where(“heightMin”, “>=”, 165).where(“heightMax”, “<=”, 185)
.where(“ageMin”, “>=”, 20).where(“ageMax”, “<=”, 30)
.where(“type”, “==”, “running”).where(“smoker”, “==”, false)
In the Cloud Firestore Documentation, it is stated that such compound queries are not possible. To me this seems like a basic feature, thus I think I might have misinterpreted the documentation. Similar post here Firestore compound query with <= & >=
This is how a document could look like:
{
"date": "2022-03-12",
"time": "18:30:00",
"withFilters": "true",
"smoker": "false",
"heightMin": "165",
"heightMax": "165",
"ageMin": "20",
"ageMax":"30",
"type": "running",
"latitude" : "y",
"longitude : "x",
"participants": "2",
}
I know that I could probably fetch everything and then filter it in the FE but this is suboptimal and costly.
Question:
Upvotes: 0
Views: 166
Reputation: 50930
Firebase also offers an Algolia Extension that can easily sync your Firestore data with Algolia. Firestore natively does not support full text search or compound queries with many filters but Algolia does.
For example, once you've copied all your existing data in Algolia, you can the query as shown below:
index.search('query', { // <-- requires some query string
filters: 'ageMin > 25 AND heightMin > 175' // ... other constraints
]
}).then(({ hits }) => {
console.log(hits);
});
This might be the easiest and scalable way as your data is present in Firestore and both are managed services. Also also has a client SDK and you can create custom API keys to restrict user access.
MongoDB does support these queries natively but you might have to restructure existing database and migrate the data. You would also have to create indexes to support your queries manually (Algolia creates them automatically unless you want to modify them).
Upvotes: 2