How to import CSV or JSON to firebase cloud firest

2019-01-12 18:33发布

Is there a way to import CSV or JSON to firebase cloud firestore like in firebase realtime database?

enter image description here

8条回答
虎瘦雄心在
2楼-- · 2019-01-12 19:21

No as of now, you can't.. firestore structures data into a different format that is, using collections and each collection has a series of documents which then are stored in JSON format.. in future they might make a tool to convert JSON in to firestore.. for reference check this out

:https://cloud.google.com/firestore/docs/concepts/structure-data

****EDIT :****

You can automate the process up to some extent, that is, write a mock software which only pushes the fields of your CSV or JSON data into your Cloud Firestore DB. I migrated my whole database my making just a simple app which retrieved my DB and pushed it on Firestore

查看更多
姐就是有狂的资本
3楼-- · 2019-01-12 19:21

This is a small modification that copies the 'id' of the document, if exists, to its path. Otherwise it will use the "for"'s index.

  ...
  ...
  } else {
    // Collection's length of is always odd.
    for (const key in data) {
      // Resolve each collection.
      if (data[key]['id']!==undefined)
        await resolve(data[key], [...path,data[key]['id']])
      else 
        await resolve(data[key], [...path, key]);
    }
  }
}

resolve(data);
查看更多
登录 后发表回答