Firebase Realtime Database to Cloud Firestore - firebase

I´m searching the best way to migrate Firebase Realtime Database Data to Cloud Firestore for a json database with many nested rows. Example:
I found nothing that could help me. For what I need the migration is the new offline functionality of the Cloud Firestore. I´m using Ionic3 (Angular5)

Actually there's no standard way to migrate from Firebase Realtime Database to Cloud Firestore, because every application or project has is unique. You have to implement your own way of migrating to Cloud Firestore. But I suggest you read the next tutorials that will help you find the best way for you to migrate:
Cloud Firestore Data Model.
Firestore Data Structure.
Important note: By the way Firebase Realtime Database supports offilne persistence: Enabling Offline Capabilities Realtime Database.

Related

How to push new data from Realtime Database to Cloud Firestore?

I am pushing data to Firebase via Zapier and it lands in the Realtime Database. However, I am using Cloud Firestore. I've looked through a lot of documentation for both services but neither seems to have answers.. (there is information on migrating but I would like to keep both DBs).
How would I push each new or updated data entry from Realtime Database to Cloud Firestore?
There is nothing built into Firebase to automatically do this.
The fastest I can think of is to build a Cloud Function that listens for the Realtime Database writes, and then also sends them to Firestore.
Alternatively, doesn't Zapier allow you to have two zaps, one that writes to each database?

How can i import JSON into Cloud Firestore

I am currently using Firebase Realtime database. I have imported JSONs into Realtime database but due to limitation of query i need to switch on Firebase Firestore.
I want to import JSONs into Cloud Firestore of Firebase.
There is no automatic conversion from Firebase's Realtime Database to Cloud Firestore. While both are NoSQL databases and part of Firebase, their data models are different, and they are not compatible in any way.
You will have to figure out how you want to map your JSON data from Realtime Database, to the collection/document model of Cloud Firestore, and then write code against the APIs of the databases to port the data over.
Also see:
Migrate Firebase Realtime Database to Firestore
Converting Firebase Database to Cloud Firestore
Firebase Realtime Database to Cloud Firestore
Blog post: Migrating from Firebase Realtime Database To Firestore — pricing and limits
Blog post: Survival guide: how to migrate from the Firebase Realtime Database to Cloud Firestore

How to switch from Datastore to Firestore in existing project?

I have an existing Google Cloud project which uses Datastore. I'm excited by Firestore and would like to switch. According to https://www.youtube.com/watch?v=SYG-BgXoJFQ it is recommended to create a new project.
Is it possible to just nuke Datastore somehow (I don't care about the data) and start from scratch with Firestore?
If not, what are the implications of creating a new project?
If there is no data written to Cloud datastore, it's possible to convert from datastore to firestore with the following steps. I tried on 2 projects and each project took 3 minutes. The user should be the project owner to attempt:
Disable Cloud datastore API
Disable Cloud Firestore API
gcloud firestore databases create --region=us-central --project $PROJECT_ID
I have another project that has little datastore entities. I deleted them and executed the steps, but received the following error. While disabling datastore API, I read Disable Cloud Datastore API? If any resources were created by Cloud Datastore API, they may be deleted soon after Cloud Datastore API is disabled. All code that uses this project's credentials to call Cloud Datastore API will fail.
ERROR: (gcloud.firestore.databases.create) Error Response: [9] The
"database_type" field cannot be modified for this application. Note:
If data has already been written for this application, then the
"database_type" may not be modified.
The solution is to contact Google cloud support to convert from Datastore to Firestore. You need to make sure no entities exist and nothing is creating any entities.
In the case where no Datastore entities have been written, the operation should succeed:
Success! Selected Google Cloud Firestore Native database for $PROJECT_ID
It is not possible to switch from Datastore to Firestore within the same project as yet, but you may operate Firestore in Datastore mode. By creating a Cloud Firestore database in Datastore mode, you can access Cloud Firestore's improved storage layer while keeping Cloud Datastore system behavior. You may find more information of relevance by reading the "Automatic Upgrade to Cloud Firestore" documentation page.

.info/serverTimeOffset for Firestore?

I am using Firebase Firestore and want to get a rough idea of the the server time. Similar to how the Realtime Database had .info/serverTimeOffset. I could create a realtime database just to use the .info/serverTimeOffset endpoint but is there any better way using just Firestore?
There is no equivalent of .info/serverTimeOffset in Cloud Firestore at the moment. That's one of the reasons we recommend using the Firebase Realtime Database for a presence system, even when you use Cloud Firestore for other data storage needs.

How to use Cloud Firestore and Realtime Database in same project

Firebase's documentation has the following paragraph:
Using Cloud Firestore and Realtime Database: You can use both databases within the same Firebase app or project. Both NoSQL databases can store the same types of data and the client libraries work in a similar manner. Keep in mind the differences outlined above if you decide to use both databases in your app.
I can't find any documentation on how to add a Cloud Firestore to an existing project with a Realtime Database, though. I will ultimately upgrade to Cloud Firestore, but would like some time to experiment and learn before I convert the production database.
Does anybody know how to use both databases in the same Firebase project?
When you go to your project in the console and choose the Database product, you should see something like this the first time:
This is a selector that lets you choose to see either Realtime Database or Firestore in your project. You can switch between the two with this selector.
The first time you select Cloud Firestore, it will ask you to configure things. Start in "test mode" to set things up for full read and write without authentication to get started quickly, but of course your should always have rules set up in production.
After you set up Firestore, you should be able to use both client SDKs to access both databases independently.

Resources