I am using Firebase in an app which we deployed a couple of months ago. Of course, a few database changes happened and a lot of new triggers were created, which we now want to deploy to production together with a new app version.
The question is how do we force the previous app version to work with the new triggers and database structure without forcing our users to update the old app? Does anyone have any experience or suggestions in implementing this smoothly?
Some examples of what did change:
A counter to keep track of like counts was set in the app code in the previous version. This now has been moved to a cloud function.
A collection named '/users' is now split in two collections '/users' and '/_users', with '/users' containing all data accessible for all users and '/_users' containing all data only accessible for admins. Also a trigger is built to keep corresponding fields synchronized (fe. the field firstName occurs in '/users' and '/_users') So when a new user is created in the previous app version, the document will contain too many fields, because some belong to the '/_users' collection now. How can this be handled?
I've found out that with remote config we'll be able to force the users to update the app, but still that ain't the way to go for us. The first scenario seems easy to counter by just recalculating the count in the trigger. The second seems a little more complex.
Related
I am working on a personal project to recreate the news feed of Facebook. So what I am trying to do is to recreate the scenario where when the user goes to the news feed, the user gets posts of everyone he follows only. Is there any way to run a query like that using the Firebase real-time database using an of "followings".
I can successfully generate single users posts in the android studio app using snapshot and recycler view.
If you're asking whether you can get posts from multiple userUID values with a single query, that is not possible.
If you're asking whether you can pass a list of postUID values to retrieve, that is also not possible.
In both cases the solution is to execute a separate query/read operation for each of the values, and merge the results in your application code. This is not nearly as slow as you may think, since Firebase pipelines the requests over a single web socket connection - which is quite efficient. For more on this, see Speed up fetching posts for my social network app by using query instead of observing a single event repeatedly
I am building a job portal for the web using React, Redux and Firebase/Firestore. I've completed all the features I needed except one.
I want unregistered-users/job-seekers to be able to:
Bookmark job posts.
Keep the record of applied jobs.
Keep the record of search queries.
I am thinking about using IndexedDB for this feature. Particularly Dexie.js to make things easier. However, this data will be persisted in user's browser and user will have no access to it in another browser or device. Therefore, I want to give users an option to be able to save all the data to Firestore if user sign into the website and I need this to be automatic. So, as soon as user signs in, I will save it to the database.
I thought about using Anonymous Authentication instead of IndexedDB/Firestore, so all the data will be saved into the database and as soon as user signs in using credentials, the user can claim the ownership of the data. However, this is an extra step to use these features I listed above and not everyone is happy with authenticating an app even though nothing is required from the user. Besides, there will be so many ghost accounts.
So, as I mentioned in the title; I want to save everything to IndexedDB (I will take care of this), but how am I going to synchronize all the data in IndexedDB to Firestore as soon as user signs in?
I imagined the basic process will be like this:
User clicks "Bookmark Job Post"
App checks if users is authenticated or not.
If authenticated, save the bookmark to the Firestore.
If not authenticated, save the bookmark to the IndexedDB.
If User decided to sign in or sign up, check IndexedDB and synchronize it with Firestore and clear IndexedDB.
How can I achieve the 5th step technically? Is there any built in system in Firebase? Also, please feel free to share your idea if you can think of another way implementing this feature. Should I be using firebase.auth().onAuthStateChanged() for the 5th step?
And lastly, how should I structure the Firestore to save bookmarked jobs, applied jobs and search history?
Should I create a bookmarkedJobs collection and have documents of jobPosts duplicated for each user, who bookmarked the job post? And every time a job post is updated by an employer, I will have a cloud function going through bookmarkedJobs collection, updating every instance of it?
Thank you
This may be of interest to you
https://dexie.org/docs/Syncable/Dexie.Syncable.js
Been looking into making my website fully static/pwa, and just using indexeddb, and some webservice for data handling/storage ..this seems like a interesting route to explore.
This question already has answers here:
Firebase Android - Only need specific table to be in local device
(1 answer)
How to limit Firebase database persistence store to only some nodes?
(1 answer)
Closed 2 years ago.
I'm working on a project where I'm using Firebase realtime database as my database. Most of my information will be online, but I want to keep some folders offline. As the documentation says, if I write
FirebaseDatabase.getInstance().setPersistenceEnabled(true)
Any data that I sync from database will be cached, but that's not the behaviour that I want.
Let's say that I have an app where user can create a lists with games
I have 2 folders on my DB root: games and userLists.
In my app I get all games from "games" folder, let the user choose some of them and save under:
userLists/(userId)/(listName).
If I "setPersistenceEnable" as true, all data sync will be kept offline, including games from "game" folder.
I want to keep only the folders under userLists/(userId)/ offline.
Is there anyway to achieve this behaviour?
It's not possible using a simple configuration. Using the provided API in the default setup, you can either choose to persist any of the data that you get from queries, or you choose not to persist anything at all.
If you need to persist only certain data, you will have to either:
Disable persistence, and arrange to persist only certain data on your own (perhaps in a sqlite database)
Enable persistence, but only use it for certain queries. Other queries can go through a different instance of a FirebaseApp where persistence is disabled, or use the REST API directly.
We are building a to-go order web application for restaurants with Firebase and Vue.
Restaurants can create their own pages, and add menu items.
Users (customers) can orders some foods from those restaurants pages, and pick them up later.
At the beginning of the project, we have chosen to store some transient data (user data, shopping carts, etc.) in the Vuex store. It works fine but there are a lot of complexities in it, which made it hard to maintain.
Recently, I have realized that we could just use Firestore for those transient data as well, which will greatly simplify the architecture, eliminating Vuex completely.
Before making all the changes, I want to make it sure that I am on the right track and I am not missing anything.
I'd really appreciate any comments and suggestions from those people who have experience in building relatively large scale web applications using Firebase + Vue (or even React).
Short Answer
Yes, this seems perfectly reasonable.
Long Answer
Many web applications have their state synchronized via an external service like Firebase, GraphQL, etc. In these cases you may already be using some kind of shared, UI-independent cache (e.g. Frestore, Apollo client). Unless the aforementioned cache cannot be easily accessed by your UI components, there would be little benefit to switching or duplicating the data to Vuex.
Keep in mind that even in the above scenario, Vuex can still be a useful tool to track UI-specific state across otherwise disconnected components in your interface. For example, you could globally identify the user's current viewing mode, or which modal is open.
Yes you can go without VUEX, however, it will limit your potential.
First of all vuex is really simple, you can easly add vuex your code.
Without Vuex you may write same code again and again.
For example you want to redirect your user to his restaurant page when he logs in. So you write a code that first checks if user has a restaurant and then gets his restaurant ids.
Also you want to check when a user opens a restaurant page, if the user owns that page, you write the same code again. However, if you have a function that returns a value if user is the owner or not. You can call it any page you want.
I'm developing a mobile application which I would like to distribute globally. The app is targeted for managers who want their employees to update data as they are on-the-go, while the manager has a web dashboard that collects and dices the data.
The architecture I would like to implement, is that the manager logs in to the product's website, creates an account, and gets a code. Employees are then asked to download the app, and enter that code upon initial setup.
My question is about the back-end implementation of the setup - I would like for each new customer to have their own firebase instance, which is automatically set up and registered when the account is created.
It seems like the API does not support creating new accounts or new repositories/instances.
Is there a way to create an account/instance using a script? If not, would one instance be able to hold potentially a very large number of tables, each table being a root for a specific customer and their data?
Thanks!