在 angularfire2 中访问另一个 firestore 数据

access another firestore data in angularfire2

我持有 2 个 firebase 项目(A 和 B),它们在 firestore 中有数据,而不是实时的。 我的用例是我需要访问其他项目的 firestore 数据。 A 应用应该能够读取和写入 B 的 firestore,反之亦然。

我试过让我们从 A 应用程序的角度来看,我们可以使用来自构造函数的 publicafs:AngularFirestore 访问 A 的 firestore 数据。但是为了访问 B 的 firestore 数据,我尝试初始化配置并采用如下所示的 angularfirestore 参考。

const secondApp = firebase.initializeApp({
          apiKey: "xxxxxxxxxxxxxxxxxxx",
          authDomain: "xxxxxxxxxxxxxxxxxx",
          databaseURL: "xxxxxxxxxxxxxxxx",
          storageBucket: "xxxxxxxxxxxxxxx",
          messagingSenderId: "xxxxxxxxxxxx",
          projectId: "xxxxxxxxxx"
          });
const secondAfS = new AngularFirestore(secondApp );

然后它以抛出错误作为结束 Expected 6 arguments, but got 1.

我不确定构造函数所需的参数,但刚刚试过了。所以错误说(对我来说),如果我们提供所需的 6 个参数是否有效?

这种用例可以实现吗?如果是这样,请纠正我。 否则,请告诉我解决方法。

快速浏览 the source 似乎无法将 FirebaseApp 实例传递到 AngularFirestore。相反,您将选项和配置传递给 AngularFirestore 构造函数,它会创建 FirebaseApp 本身。

所以像这样:

const secondConfig = {
          apiKey: "xxxxxxxxxxxxxxxxxxx",
          authDomain: "xxxxxxxxxxxxxxxxxx",
          databaseURL: "xxxxxxxxxxxxxxxx",
          storageBucket: "xxxxxxxxxxxxxxx",
          messagingSenderId: "xxxxxxxxxxxx",
          projectId: "xxxxxxxxxx"
          };
const secondAfS = new AngularFirestore(secondConfig);

此时,我没有找到调用另一个 firestore 数据库的选项,但我们可以调用另一个实时数据库。所以我设法通过在另一个应用程序的实时数据库中添加数据库触发器来实现我的功能。