英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论