Adding COMPLETELY FREE full text search capability to Cloud Firestore [duplicate] - firebase

This question already has answers here:
Search by pattern on Cloud Firestore collection
(1 answer)
Google Firestore: Query on substring of a property value (text search)
(25 answers)
Closed 4 years ago.
My client has a project based on Firebase. They want me to add some functionalities to its core, and make necessary changes on client applications. One of the new functionalities requested is text-based search on Firestore documents. But this solution should be totally free.
According to Firebase docs I may use Algolia or ElasticSerach or an equivalent of these. But to use these services I should pay for the service, or rent a Google Cloud Platform or AWS deployment, or a standard dedicated server, and all of these solutions requires periodical payments.
So, in the end, I've 2 solutions.
1. Search on Client
Query all documents and perform the search on them.
2. Use Cloud Functions
Query all documents in cloud functions and return the search result.
Both approaches will increase the Firebase usage. This might cause limit excess and unintended invoices.
My question is, Is there any free search service? Do you have a better idea than mines? If you don't; which approach is better?

Related

Deciding when to use firebase cloud functions instead of only firestore client sdk [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I know there’s no correct answer, but I would like to hear your thoughts on a specific example:
Say you have restaurant, and this restaurant has a ordering system with 3 applications:
for the restaurant ‘boss’ (for a lack of a better word).
for the delivery guys.
for the client (ordering food).
Works more like an admin account. Therefore I have decided to use cloud functions with the admin sdk to add new users i.e delivery guys accounts. The constructions of menus and dishes are all happening here. I’m currently using only the client sdk for this, simply because it's fast for such simple tasks and cache is a big plus. Now, security wise, my thought is that the ‘boss’ wouldn’t want to tamper with his own documents, so allowing him read and write access to all documents here via security rules seems fine. Would like to hear your thoughts, though.
Now, this one is a bit harder, because I’b been only using the client sdk here and allowing read and write access to orders documents for delivery guys. This may be a bit naive since allowing write access to a delivery guy opens up the possibility for tampering with specific fields on the orders doc. I decided to do it that way simply for the speed and cache, but now I’m thinking that I should change it. There is also a chat functionality between the ‘boss’ and the delivery guys. I’m using one document per conversation and if it exceeds 1mb, I have a cloud function that archives older messages if this limit is approached. But since all reads and writes to the chat doc can happen from the delivery guy via client sdk, this leaves it a bit open security wise also (even with more complex security rules). I might be able to solve this if I stopped using one doc and had a doc per message. And with some good security rules I could make this a bit more secure, but not compared to using a cloud function.
Here, I have not coded anything on the front end at all, I’m thinking of using cloud functions for security when order requests are submitted.
I really like the speed (for simple queries) and cache when using the client only. If I have something a little more compute heavy or complex I have used cloud functions, which works fine. I also like using cloud functions to trigger stuff after the client sdk has done something. My big concern using cloud functions as a sort of a wrapper or middle man for simple queries too, is the speed on cold starts (and sometimes it’s a bit slow after it's spun up compared to only using client sdk). I’m not a big fan of losing cache and streams that I have with the client sdk. But, since security is very important I’m a bit twisted on what to do.
I’m not asking for any code or the perfect answer, just your thoughts and if you have had any experience with this. I’m leaning towards sticking to the client sdk even for the delivery guys and try to moderate this through even better and complex security rules. And then, maybe try to exploit it myself to see how good it is. What are your thoughts?
I’ve read this article which I found useful: https://medium.com/firebase-developers/should-i-query-my-firebase-database-directly-or-us
And watched the video series on cloud functions by firebase, and I found the docs really helpful (both cloud functions and firestore).
Whenever you need to handle sensitive information that the client could compromise or manipulate beyond what Security Rules can prevent, you should use Cloud Functions as a source of authority.
Firestore + Security Rules
Firestore + Security Rules
Firestore + Security Rules
Cloud Functions only work with the admin-sdk, you can't use the client modules successfully in a node.js environment.
Security Rules are your friend, you can deny writes and updates specifically - Chat should be managed through the realtime database
use Cloud Functions to finalize orders, cross reference prices, etc. but the rest can be done with Firestore and smart Security Rules to prevent illegal edits.
Additionally, you can use Custom Claims to denote who has what role and validate who can do what with rules. so only boss's can issue refunds, wave costs, etc.
Reference:
https://firebase.google.com/docs/firestore/security/rules-conditions#data_validation
https://firebase.google.com/docs/auth/admin/custom-claims

GET Firebase Statistics via API [duplicate]

This question already has answers here:
Firebase analytics from remote REST API?
(3 answers)
Is there any api for dashboard analytics data?
(1 answer)
Closed 2 years ago.
I am looking for an automated way to pull down the some of the high level usages statistics via an API or persistent csv location with credentials.
You can see that the linked image that firebase provides a 'data-export.csv' file, under the Analytics menu .
Is there a way to do this, either directly from Firebase via an API, or via an integration with Google Analytics (I assume is the backend to firebase analytics), or via say a clever python script? Reason being is we want to share some key info in organisational business intelligence reports.
I have scanned the forums without a clear solution or no its not possible. Any assistance or examples of success (or failure) experiences and approach would be appreciated? Thx

Let client add data to Firestore through HTTP POST cloud function (Architecture) [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
So I'm building a web shop using Firestore and Firebase for the first time, I'm also new to NoSQL. I have the following architectural problem: When a customer places an order the client sends the products ordered to Firestore directly which stores the order in a collection raw_orders. My idea then was to have a Cloud Function trigger on the document create which processes it and builds an invoice and such. However I read that this function invocation may be delayed for 10 seconds, I would like to have a synchronous solution instead.
Instead I had the idea to create a HTTP Cloud Function where the customer can POST the order to, the HTTP function then processes the order and pushes it to Firestore, the function then returns the orderID or something to the customer. This approach feels much more safe since the user won't have to talk to the database directly. Also it solves the issues that the a function triggered by a Firestore create might be delayed.
However I'm new to Firebase and I'm not sure if this is architecturally the preferred way. The method I propose seems to be more in line with regular old REST APIs.
What do you think?
Thanks!
It sounds like you definitely have some server-side code and database operations that you can't trust the clients to do. (Keep in mind that firestore security rules are your only protection -- anyone can run whatever code they want within those rules, not just the code you provide).
Cloud functions give you exactly this -- and since you both want the operation to be synchronous (from the view of your client) and presumably have some way for the client to react to errors in the process, a cloud function would make a lot of sense for you to use.
Using cloud functions in this way is very common in Firebase apps, even if it isn't pure REST.
Moreover, if you are using Firebase more generally in your client, it might be more natural to use a callable cloud function rather than an http function, as this will handle the marshaling of the parameters in a much more native way than a raw HTTP request might. However, it isn't clear in your case since it sounds like you're using the REST API today.
Keep in mind that there are additional costs (or specific quotas, depending on your pricing plan) for running cloud functions. The pricing is based on invocations, as well as CPU and RAM usage of your functions.

Firebase Realtime Database or Firestore for chatting app? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
We are building a chat app, one-to-one chatting is the main purpose of the app so for now, messaging speed is our first priority. We need a backend solution and we were initially planning to use Firebase realtime database. But then Firestore came to existence, from there onwards we saw a lot of recommendations for Firestore over Realtime database from the Firebase team.
We have used both Realtime Database and Firestore so we are pretty aware of the capabilities and querying powers of both. For our use case in terms of features, any of them are fine. But as I told before our main concern is messaging speed. So which one is more realtime?
So which one is more real-time?
I don't think one is more real-time than another.
But then Firestore came to existence, from there onwards we saw a lot of recommendations for Firestore
That's right, Firestore has some new features over Firebase Realtime Database, that's why is named "the new flagship". The query performance depends on the number of items you request and not on the number of items you request them from. So every time you think to get data, get it in such proportion to maintain the speed that you were talking about. As the guys from the Firebase team say, Cloud Firestore has a performance guarantee, there are no slow queries, so the time it takes your app to retrieve data depends on only on the amount of data you retrieve and not on the amount of data you have on Firebase servers. In other words, it doesn't matter if you have one thousand, one million, or even one billion documents within a single collection, retrieving for instance 15 of them, will always take the same amount of time.
This performance comes with some constraints and for that, I recommend you take a look at all sections within the official document regarding getting data in Cloud Firestore. That's the reason why Firestore uses those constraints, is due to the fact that is mandatory to maintain this performance guarantee. But from my experience, there is no "SQL" query that cannot be translated in a way or another in Cloud Firestore.
So remember, it really does not matter if you request a single document out of a 10 or one item out of 100.000 or 100.000.000.000, the result will come in the exact amount of time. Here I took as an example one document. So regarding speed, requesting one document out of 100 million will be faster than requesting 10 items out of the same 100 million. So the number of documents in the collection has no effect on the query performance.
This is about Cloud Firestore but there two main resources that I recommend you read before using one or another:
https://firebase.google.com/docs/database/rtdb-vs-firestore
https://firebase.googleblog.com/2017/10/cloud-firestore-for-rtdb-developers.html
So check the price models for each one of them. But IMHO, both Cloud Firestore and Firebase Realtime database work extremely fine together.
In my opinion calculation is simple. Realtime database 10 000 M chat messages data transfer = $490. Firestore 5 000 M reads = $3000 and 5 000 M writes $9000 = $12000. So the cheapest way is to use realtime database and because of $5/GB stored you need each few weeks/months rewrite messages to firestore. For chat app like discord where you have conversation shared with many users the best way is to set a server witch different database like Cassandra.

How would I change a certain field of a document every 3 hours with Firestore? [duplicate]

This question already has answers here:
Cloud Functions for Firebase trigger on time?
(3 answers)
Closed 4 years ago.
I’m making an app that requires every 3 hours to update a certain field of a document. How would I do that?
You're looking for something called "Cron Job".
The Idea behind it: You create an HTTP triggered method in Firebase Functions, and assign an outer service (for example: Google App Engine) that is responsible to send the HTTP request routinely.
There isn't any Firebase-built-in solution, but you could use Google App Engine / other Cloud utility available out there.
Here's an Excellent article for implementing one with Firebase Functions.
This one might help as well (Firebase Blog).

Resources