dalenguyen / firestore-import-export

An application that can help you to backup and restore from Cloud Firestore | Firebase
https://www.npmjs.com/package/firestore-export-import
401 stars 109 forks source link

Subcollections are created as objects #10

Closed germanandrade closed 6 years ago

germanandrade commented 6 years ago

I have a simple database with games>users and when I get the exported I have a json like this

{
   "games":{
      "21hRLgKFxGDep7s7bDyY":{
         "Date":1536256816002,
         "State":"COMPLETED",
         "users":{
            "ElaQCEJxQlNmECwei1SFQ1nqs4y1":{
               "Debt":0,
               "Endavans":56000,
               "Id":"ElaQCEJxQlNmECwei1SFQ1nqs4y1",
               "LifeSavers":0,
               "Name":"kevin el original",
               "Active":false,
               "Admin":false
            },
            "EukvVjXCwOO6aSl5bkXjTZK2RJ52":{
               "LifeSavers":0,
               "Name":"cris",
               "Active":false,
               "Admin":false,
               "Debt":0,
               "Endavans":18000,
               "Id":"EukvVjXCwOO6aSl5bkXjTZK2RJ52"
            },
            "QZPw7rhpimQiptje2OamYixrUWy2":{
               "Endavans":0,
               "Id":"QZPw7rhpimQiptje2OamYixrUWy2",
               "LifeSavers":0,
               "Name":"Ger",
               "Active":false,
               "Admin":false,
               "Debt":0
            },
            "zwNfvrE6YYPAwcNtCD9GrXT6BHh1":{
               "Debt":0,
               "Endavans":58000,
               "Id":"zwNfvrE6YYPAwcNtCD9GrXT6BHh1",
               "LifeSavers":0,
               "Name":"L",
               "Token":"ckRLEEq6Fw8:APA91bG9djdyN1kNzta9hU0OYE8Zaaf2dV2fOmxjcOOh602yRV8bsoRrCuP0mULUJhvM85FEOjCThow6XBnANaypFHITXBOXfPH94uL9pOh5UcJjgwAZaXsFn8pO5_NhCh2EL8c_1DJC",
               "Active":false,
               "Admin":false
            }
         }
      }
   }
}

But once i import that i have this: image

Instead of something like this:

image

Is there any way to accomplish that?

Btw nice project!

Thank you for your time!

Regards,

Germán.

germanandrade commented 6 years ago

I just found a way to insert the users as subcollection, instead of use .firebaseio.com I used

.firebaseio.com/games/21hRLgKFxGDep7s7bDyY and it worked perfectly!
dalenguyen commented 6 years ago

Hi @germanandrade, there's a subcollection argument that you can use to add the subcollection, but your method still works :)

samyoungnyc commented 4 years ago

Hi @dalenguyen thanks for this library. Can you pls let me know what the argument for adding the subcollection is? thanks

dalenguyen commented 4 years ago

Hi @samyoungnyc, please use this package for the updated features: https://github.com/dalenguyen/firestore-backup-restore

samyoungnyc commented 4 years ago

OK - I am using it- when importing a particular collection/subcollection - do I have to name the collection in the restore method call? Is that what the refs option is for?

Example:

firestoreService.restore('userCollection.json', {
  refs: ['refKey', 'arrayRef'],
});
dalenguyen commented 4 years ago

@samyoungnyc, for subcollection, you have to structure your JSON file by following the example in order to import the subcollection. https://github.com/dalenguyen/firestore-backup-restore/blob/master/test/import-array-to-firestore.json

It should be inside a subCollection object.