Updating clients when changing Firestore collection name and structure

141 views
Skip to first unread message

Andrés Manikis

unread,
Dec 11, 2022, 4:41:15 PM12/11/22
to Firebase Google Group
Hello everyone. I have the following question.

I have a collection in Firestore and I need to change its name and also the structure of the fields (i.e. change data types, and rename fields).

If I go ahead and make the changes, any web clients (I only have web clients) that haven't reloaded the app with the necessary updates for querying the new structure will have issues connecting to Firestore. For example, they won't be able to find the renamed collection or may write things to fields using the old field names.

Is there a best practice on how to handle this type of scenario?
I can think of somehow forcing a reload of the web clients as soon as I update Firestore but maybe there's a better way.

Best regards,
Andrés

Kato Richardson

unread,
Dec 12, 2022, 1:24:00 PM12/12/22
to fireba...@googlegroups.com
Hi Andrés,

Great to meet you.

A known approach here is to build out a function trigger that watches for updates in the new collection and dual writes them to the existing/legacy collection. Once you feel a sufficient percentage of your app instances have upgraded, then you can delete the function, disabling the dual write. This allows you to control the cutoff window and maintain some backward compatibility.

An elegant solution for the future might be to keep a version number in your database and monitor it from the client for changes. When it is bumped, you can show an alert on the clients to reload, mitigating the need for complicated upgrade paths. This is pretty common in enterprise apps I use through the web.

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/55e10aad-ceeb-47a1-85be-fde7ead27b12n%40googlegroups.com.


--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Andrés Manikis

unread,
Dec 16, 2022, 3:03:33 PM12/16/22
to Firebase Google Group
Hi Kato, thanks for your answer, it makes a lot of sense and I'll probably use the one about keeping a version that I can monitor for changes.

Best regards,
Andrés
Reply all
Reply to author
Forward
0 new messages