firebasegoogle-cloud-firestoregoogle-realtime-api

How can I use undo | redo or in google cloud firestore?


I am trying to migrate app from Google Realtime to Google Cloud Firestore as following reason.

Important dates to note

As of November 28, 2017, Realtime API is no longer available for new projects. Google API Console projects which accessed Realtime API prior to November 28, 2017 (including your projects listed above) will continue to function normally until December 11, 2018.

On December 11, 2018, Realtime API documents will be made read-only, and attempts to modify document contents using the API will fail.

On January 15, 2019, Realtime API will be shut down, but an endpoint to export document contents will remain available.

Realtime API supports versioning for document. https://developers.google.com/google-apps/realtime/migration

function retrieveRealtimeJson(docId, revision) {
  gapi.client.drive.realtime.get({
      'fileId': docId,
      'revision': revision   // =====> can get previous version of doc
    }).then(function(response) {
      return response.data;
    });
  return null;
}

Also Realtime API supports UNDO and REDO. https://developers.google.com/google-apps/realtime/undo

if (model.canUndo) {
  model.undo();
} else {
  console.log("No events to undo.");
}

Is there a equivalent function of undo and redo or fetching revision in Google Cloud Firestore ?



Solution

  • Cloud Firestore does not have built-in versioning of documents.

    If your use-case requires versioning, you will have to build that on top of the Firestore API yourself.

    For example, you could make the versioned content a subcollection of each document, so that each version is a separate document in a subcollection: /documents/document1/versions/1, /documents/document1/versions/2, etc.