What's the best way to store static data in firebase - firebase

I'm writing firebase android app in android studio. I have almost 2000 geo locations and I want them to be marked on map all the time. Firebase databse isn't good idea to store such data because this is static data. So firebase storage, hosting, just some list in code or something different would be the best way?
Thanks in advance

For static data, you could use list and append all the geo locations with push() method. The push() method generates a unique key every time a new child is added to the specified Firebase reference.
By using these auto-generated keys for each new element in the list, several clients can add children to the same location at the same time without write conflicts. The unique key generated by push() is based on a timestamp, so list items are automatically ordered chronologically.

For static data that you create yourself, I'd use Firebase Hosting. It gives you a simple way to update the data with firebase deploy, and comes with a built-in CDN.
For unstructured data that your users create, use Cloud Storage for Firebase.
For structured data that your users create, use Cloud Firestore or the Realtime Database.
Also see: Firebase : Differences between realtime database and file storage

Related

Is it possible to reset, and recreate firestore?

I'm trying to migrate my firestore database to a new location, since google added a new Canadian region after we created our database in US-West.
The standard answer is you can't change the location of firestore after creating it. The only way
I've heard is possible is to create a completely new project. Obviously that has many down-sides.
However, I was wondering if its possible to reset and recreate firestore in the desired region within the original project as a work-around? That way I wouldn't need to create a new project.
The steps would be as follows:
Export firestore data to google cloud storage
Move exported data to a new storage bucket in the desired region (You can't run firestore import across regions)
Reset firestore
Recreate firestore in the desired region
Import the exported data into firestore
For now it is not possible to change the region for a Firestore instance already created as mentioned in the docs and you may need to migrate all the data to the new project.
Anyway there is already a Feature Request so the location can be changed at any time in the same project

Find n nearest locations in flutter: local database (Sqlite) in combination with Cloud Firestore vs Firebase Realtime Database

I am working on the following topic right now:
about 8000 stores/objects(uniqueID, name, adress, latitude, longitude, geohash, amount of productX, amount of productY.)
in the future there will be new stores and also some of the stores will be deleted
I am planning to add a version attribute to each data: for example I start with version1. If I receive an update or a new store then it will have version2
it is not needed to receive realtime changes. This data will be changed only a couple of times each month
Flutter app with a feature: find n stores at this location
because the data is not changed frequently I was planning to put an updated local sqlite database to each build
I will use Realtime Database or Firestore to receive updated data within my app to avoid to publish a new version only because database was changed
Firestore: I will add only a new attribute to my document and I will request all data that is newer than my local database version and I will also have a collection that has all deleted items
Realtime database: here I would have something like this
-updates
version1
newData: List of unique IDs
deletedData: List of unique IDs
I read a lot about geo queries on firestore and I also found a working flutter plugin to do this filtering on serverside, but because my data is not changed that frequently I am very confused about the best approach.
Questions:
Is my approach a good idea or should I forget about the local sqlite DB and use only Firebase/Firestore?
If I will use the local database and will only observe updates from the backend, which of the services should I use in terms of pricing etc.? (Advantage Firestore: If I use Firestore I can easily switch to it by using the flutter plugin and forget about my local database)
If you have only a couple of thousand objects, and the data hardly every changes, I'd typically consider querying the data locally on the device. You can likely very quickly iterate over the 8,000 items to check their lat/lon against the user location.
You could then use something like Firebase Storage or even Firebase Hosting to distribute updated data sets to the users. Of course you could use Firestore or Realtime Database for that too, but if you're not using their querying or realtime capabilities, there are cheaper options to distribute a static file.

How to get all the images from firebase storage in flutter?

Is there a way to get all the images(files) from firebase storage. It doesn't have the listall() function in flutter. If there isn't way to do this, can we get images by their metadata? I don't want to get them by their names.
Until proper file listing gets added to the API, you don't really have a way to do this from Flutter. Your best options are to:
Build a backend endpoint that can use one of the server SDKs to list objects from Cloud Storage. Query that endpoint from your app.
Make a record in a database for each file, and query the database instead. Make sure to keep the bucket and database in sync.

Is there a way to perform a transaction that writes to auth, firestore and storage

I'm new to firebase and I want to add it to my vuejs project.
But I'm wondering. Is the a way I can perform a transaction that creates user using the auth() and use the uid to create a user using firestore() and use the uid as a name to upload an image using storage(). However, the whole operation should revert, should any fail.
There are no cross-product transactions available for Firebase products. Of the three products you mentioned, only Firestore has transactions, and they are limited to documents within a single database.
What you will have to do is check for errors each step of the way, and undo any previous changes if something fails.

Is it possible to mix certain data types in Firebase?

I'm wondering how to store this kind of data structure into Firebase
What i have learned so far from Firebase Docs was that if we want to store JSON, we could use Firebase Realtime Database. But, if we want to store Images/Video/Files, we could use Firebase Storage.
The issue is i want to store both kind of data (string, and image). Any idea how can i achieve this ?
Put your files in Cloud Storage for Firebase, then store a URL or path to the file in Realtime Database. It's strongly recommended not to store large amounts of binary data in Realtime Database - that's simply not what it's good for.

Resources