Firestore合并两个集合成一个

huangapple go评论49阅读模式
英文:

Firestore merge two collections into one

问题

有没有办法将这两个Firestore表合并成一个?在Firestore中合并两个表。

英文:

I am working on a project where we have an iOS and an Android app and we are using Firestore as the backend. Now I have discovered that we write the same data in two separate collections.

For example, we have the class user, with id name, etc.
Android writes it in the user collection and ios in the basicUser collection.

Is there a way to merge these two tables into one in Firestore?

Merge two Firestore tables into one.

答案1

得分: 1

不,没有工具可以帮助您将两个集合的文档合并为一个单一的集合。您需要做的是将一个集合中的文档复制到另一个集合中。此外,为了避免将来出现问题,请确保在iOS和Android应用程序中使用相同的名称。例如,如果您考虑使用user集合的名称而不是basicUser,那么请确保两个应用程序在代码中都使用完全相同的user名称。

在我看来,解决这个问题的最佳选择是使用Firebase的云函数

附言:在将所有文档从一个集合复制到另一个集合后,还要确保删除旧集合中的文档。

英文:

No, there is no tool that can help you merge the documents of two collections into a single one. What you have to do, is to copy the documents in one collection to the other collection. Besides that, to avoid future issues, keep the same name in both iOS and Android applications. For example, if you consider using the name of the collection user instead of basicUser, then make sure both applications use the exact same user name in the code.

IMH, the best option that you have to solve this issue, is to use Cloud Functions for Firebase.

P.S. After you copy all documents from one collection to the other one, make also sure to delete the documents from the older collection.

huangapple
  • 本文由 发表于 2023年3月7日 17:04:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75659878.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定