How to transfer my Firebase Realtime database to Firebase Cloud Firestore

后端 未结 4 1086
萌比男神i
萌比男神i 2021-01-03 08:47

I\'m already using Firebase Realtime database, but now Firebase has launched Cloud Firestore for database so, how can I transfer my data from realtime database to firestore

相关标签:
4条回答
  • 2021-01-03 09:14

    i made a script for converting data from firebase to firestore

    import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';
    import { AngularFireDatabase } from 'angularfire2/database';
    constructor(
    private afs: AngularFirestore,
    private angularfire: AngularFireDatabase
    ) { }convert() {
    this.itemsCollection = this.afs.collection('requests'); //ref()
    this.angularfire.list('/requests/').auditTrail().subscribe((data: any) => {
      _.each(data, element => {
        this.itemsCollection.doc(element.key).set(element.payload.val())
          .then((result) => {
          });
      });
    });}
    
    0 讨论(0)
  • 2021-01-03 09:22

    I don't recommend you changing now, its is still in its BETA version and they are coming up with new things every now and then. I suggest to wait. Let them make up their mind first :P

    0 讨论(0)
  • 2021-01-03 09:31

    Firebase has published a guide for migrating from Realtime Database to Cloud Firestore.

    Edit: It seems they have changed that page. Here is a cached version of their migration guide published earlier.

    0 讨论(0)
  • 2021-01-03 09:34

    If you're looking for a magic button that can convert your database from the Realtime Database to Cloud Firestore, there isn't one! And as far as I read, Firebase creators won't create one. So unfortunately, you'll need to convert the database yourself.

    0 讨论(0)
提交回复
热议问题