Sync Firestore with Realtime database

Viewed 364

I have my flutter application connected with firestore.

But when it comes to the IOT component that works with my app i have to use the realtime database. How can i auto update the firestore data with the realtime database

Example


Realtime
Vehicle -> ABC123 -> latitude:3.256


Firestore
Vehicle -> ABC123 -> latitude:3.256

Auto sync of the databases within a specific period time

1 Answers

You just need to create a Cloud Function that watches for changes in the Realtime Database and writes those changes to Firestore.

Something like this (untested but should get you started):

exports.syncFirestore = functions.database.ref().onWrite((change, context) => {
  const db = admin.firestore();

  db.document(change.after.key).set(change.after.val());
});
Related